This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Are there any reserved words in SQLite?
I have a big database (veekun's pokedex for those who know of it) and one table has a column named "order". It's for sorting purposes, and I'm trying to ORDER BY that column, but it is a problem since ORDER is, of course, a reserved word. The two options I see are
Rename this column (but I'd like to avoid modifying the database as much as possible)
Get around this somehow
So, in the case of 1, how would I go about renaming the column without messing up the database too much?
In the case of 2, I can't imagine what I could do, but maybe there's a trick I don't know of to get around this.
I'm using SQLite and PHP.
you just need to surround keyword collisions in `backticks`
Some databases support ` as escape character, others use […]. Looking up SQLlite's, it supports brackets:
order by [Order]
should work.
Related
I have a database with many columns all with year names. Inside of them on every row are numbers with a type of integer. I want them to all have thousand seperators (A dollar sign would be nice but I can add that in easy with php).
-What I have now is the following:
SELECT *, format(`2015`, 0) AS `15`, FROM `FullList`
and that gives me the seperators like 1,000,000. The problem is I would have to do that for every column that seems wrong.
in my php I use this as simply
<div class=\"example\">$".$row[`15`]."</div>
Giving me $1,000,000
I'm hoping to find a good way of doing this in SQL or maybe even PHP so that I don't need to use format on every column.
Databases should not contain formatting because you are storing information in a standard form which can be read by any application regardless of language. I suppose the column is currently of data-type float(11,2) or something similar, which is correct and recommended.
Though it may seem tedious to add a dollar sign in front of every value, displaying a value should be the job of the templating language (in this case PHP) and not the database.
You might want to use PHP's money_format() instead:
http://php.net/money_format
Thanks in advance for any help!
I have several different mysql columns (which are imported from a product feed) that I'm trying to convert into one to work with a custom plugin for Opencart.
The format of the MYSQL entry for the plugin is as follows...
a:11:{i:13;s:3:"964";i:14;s:9:"Automatic";i:15;s:3:"FWD";i:16;s:15:"Gas I6 4.2L/256";i:17;s:5:"Black";i:18;s:4:"Gray";i:19;s:12:"Some City, ST";i:20;s:2:"15";i:21;s:2:"21";i:22;s:6:"128365";i:23;s:17:"2XXXXG3XXXXH5XXXX";}
As you can see, the "s:X" represents the character count for each entry. I have 11 different columns with the info I'm trying to convert to this format, but without an accurate character count the plugin throws an error. So i'm trying to use a combo of sql/php to get an accurate character count that I can use to make this work. I have a handle on everything else.
SO!
My question is...how do I assign the character count to a variable? I did some googling and I found this...
SELECT CHAR_LENGTH('TABLENAME');
I realize there's more to it, just wondering how to set it as a variable.
AND
Not terribly important, but does anyone recognize the format? I've never seen this before!
Serialized PHP Array
Not sure if this will help anyone in the future since this is pretty specific, but based on the info I got from jraede (thanks alot!). I was able to load all 11 columns into a PHP array and serialize, then upload to DB. WAY easier than trying to create 11 variables for character count!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
MySQL full text search with partial words
I have a search feature on a website I'm working on (basically a directory website with business listings) that uses MySQL's FULL TEXT searching. Nothing fancy and it works reasonably well.
What I'm wanting to do is create an autocomplete search input on the site that will automatically show keywords as you type. So if I type "plu", plumbers, plumbing, pluto, etc.
For me to accomplish that, do I need to store keywords for each business listing? I've seen scripts that will extract keywords from an input. Or can I generate keywords from all listings in the database? Not really sure what the best want do this is.
The following answer shows you how to do searching on substrings
MySQL full text search with partial words
(MATCH (a.article_name) AGAINST ('MySQL*' IN BOOLEAN MODE))
It only supports subqueries matching the beginning of keywords, according to that answer
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?
I'm creating the image hosting website. I need to create a unique and five letters string (case sensitive) for an image, like an example -> imgur.com/srM0U
I have seen many examples, but they are not unique or not case sensitive.
Generated string I will use for an image filename, I think imgur uses a unique strings.
Please help with a piece of code
http://kevin.vanzonneveld.net/techblog/article/create_short_ids_with_php_like_youtube_or_tinyurl/
The main thing to keep in mind is that the way most short-URL systems work is that they save the long form URL into a database, with an auto-incremented ID. That ID is then converted to an alphanumeric short code by a script similar to the one above.
The reason I point this out is I think you're approaching the problem backwards- trying to assign an alphanumeric shortcode first. It's much easier to have unique numeric values (hence, auto-increment) and then approach encoding it from there.
Sorry for the poor formatting, sent from my phone.
I am using MySQL fulltext and PHP (codeigniter) to search a database containing RSS items. Problem is some of these items's titles use underscores instead of spaces. Since MySQL considers underscores as part of a word, these items will never be matched in the search, unless the user types the exact title including underscores.
Server is shared so I don't have access to MySQL Server System Variables.
Can this behavior be changed in some other way?
Can this maybe be done through the search query itself?
I know I could just replace all underscore occurrences in the DB by spaces, but this would compromise the original integrity of those titles though. Just wondering if there's another way of doing this.
I know I could just replace all underscore occurrences in the DB by spaces, but this would compromise the original integrity of those titles though. Just wondering if there's another way of doing this.
You can instead of replacing underscores in original title field, use a separate field dedicated to fulltext searches.
This allows you to replace underscores, plus aggregates keywords into this field (category names, authors, tags, etc.) to enhance search results relevance.
We used this a lot of times with success for getting rid of HTML tags in content infering with search
I don't think this can be done without access to the server. The only way I have ever seen to do it is the first comment on this mySQL manual page ("How I added '-' to the list of word characters"). It requires stopping the server and changing internal configuration.
Your best bet is probably creating a second column with removed underscores, and to search that.