unique strings from string column type in mySQL
| From: | Mike Krisher | Date: | Wed, 27 Feb 2002 16:09:40 +0000 |
| Subject: | unique strings from string column type in mySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-86425@lists.php.net to get a copy of this message | ||
I have a column in a database with a column type of string that holds
catalog numbers. They can be in two formats.
1: 410998
2: 555336-18
The 18 in the dash number represents a length. So there could be multiple
entries with the same base, just a different int after the dash.
I am experiencing two issues: First, when using the catalognumbers in a
SELECT statement, only those without dashes return anything. Is there
something I need to do with my datatype in order to use:
$item = "555336-18";
$sql = "SELECT * FROM products WHERE catalognumber = $item";
Second question, when I strip off the dash and following int(s), my select
statement will work, even though the subtring I am then searching for
doesn't really exist in the database. And if I have two numbers with that
same subtring base they are both returned. For Example:
$item1 = "555336-18";
$item2 = "555336-7";
$item = substr($item,0,6);
$sql = "SELECT * FROM products WHERE catalognumber = $item";
Both items will be be returned, even without using %LIKE%. I'm guessing this
all stems from my column type. Should I change it to something else, and if
so what? Can anyone help out?
Thanks,
>> Mike Krisher