| Author |
Topic |
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 03:06:22
|
Hello everybody.I have a little problem with a sql string comparison.I tried to use the following code to compare a row to a variable toget a result..The code works fine if the variable is a number like: 12345But if I use letters and numbers like: AZ1234 It doesn't work. $database->setQuery( 'SELECT task_id FROM #_projects WHERE title = '.$jid ); What am I missing..??Hope you can help me..Best regardsAllan. |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-11-08 : 03:13:51
|
| Are you using MS-SQL Server ? |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 03:18:31
|
| Hi, I am using Apache MySQL. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-08 : 04:39:12
|
| try$database->setQuery( 'SELECT task_id FROM #_projects WHERE title = ''.$jid''' );MadhivananFailing to plan is Planning to fail |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 04:41:07
|
No. He should use the LIKE operator. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 05:16:46
|
| Hi Madhivanan, Thanks for your suggestion, but that gave me a parse error..Hi webfred, Thanks for your suggestion, I have tried the LIKE operator, but it gave me the same result as =Best regardsAllan |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 05:22:00
|
Yes. When using LIKE then you need also to use a joker.I don't know sure how write it in PHP or whatever you are using but the builded query in your example should look like this:SELECT task_id FROM #_projects WHERE title LIKE '%12345' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 06:27:20
|
| Thanks webfred, I have tried, but can't get a working syntax with the PHP.I could really use some help on this one.Best regardsAllan |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 07:16:38
|
| Problem solved with following code: $database->setQuery("SELECT task_id FROM #_projects WHERE title = '".$jid."'"); Best regardsAllan |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 07:20:47
|
And where is the joker?$database->setQuery("SELECT task_id FROM #_projects WHERE title = '%".$jid."'"); Without joker (%) you are not solving your problem to find 12345 in AZ12345 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 07:52:06
|
| Hi webfred,The joker is not needed, I wanted to match to entire string with characters and numbers combined.With out the quotes, the request returned empty when characters and numbers combined. Only worked with numbers..Best regardsAllan |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 08:01:29
|
So your 'It's not working' in your first post doesn't mean you wanted to search a part of the string.The meaning was a type mismatch?Then you should not use the LIKE operator and what you have shown above:$database->setQuery("SELECT task_id FROM #_projects WHERE title = '".$jid."'"); is fine.My bad was, I have not noticed in your posted solution there was no LIKE anymore... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
allanim
Starting Member
7 Posts |
Posted - 2010-11-08 : 08:26:52
|
| Yes, Should properly have explained my self a little better :-)Thank you very much for your help..Best regardsAllan |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 08:44:13
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|