| | |
variable in WHERE...LIKE construct doesn't work
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
why does
find 23 records, but
finds none? Shouldn't they be the same?
Can I not use a variable as a parameter for LIKE? Or is it a data-type issue (e.g. $testvalue is storing as a number rather than a string?)
Looks to me like these should work the same. I'm baffled (but then that's nothing new...)
Thanks,
~kyle
MySQL Syntax (Toggle Plain Text)
$sql = 'SELECT userid FROM `phplist_user_user_attribute` WHERE `attributeid`= 7 AND `value` LIKE "68104"'; $query = mysql_query($sql);
MySQL Syntax (Toggle Plain Text)
$testvalue="68104"; $sql = 'SELECT userid FROM `phplist_user_user_attribute` WHERE `attributeid`= 7 AND `value` LIKE "$testvalue"'; $query = mysql_query($sql);
Can I not use a variable as a parameter for LIKE? Or is it a data-type issue (e.g. $testvalue is storing as a number rather than a string?)
Looks to me like these should work the same. I'm baffled (but then that's nothing new...)
Thanks,
~kyle
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
got it figured out. Somehow an escape character was getting inserted in my $testvalue (in real use I was reading values from a file, and the linefeed at the end of each record was getting read into the variable, though why it would happen in the above "hardcoded" example beats me)
I solved the problem by replacing
with
that seemed to fix it
I solved the problem by replacing
$testvalue = $zlist[$i];with
$testvalue = trim($zlist[$i]);that seemed to fix it
you dont seem to be using any wild cards for your query, so you probibly dont even need to use like
also in your example you had your query in double quotes inside of single quotes, this means that you were looking for $testvalue literally and not the variable.
MySQL Syntax (Toggle Plain Text)
SELECT * FROM table WHERE id LIKE '123%'
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
That makes sense to me, but I don't think it's true. If I put the variable in single-quotes the script just crashes. It works well now - it's in double-quotes, but the selection is definitely using the value of the variable, not the literal string.
As for the use of "LIKE", some of the zipcodes in the database are 9-digit, the wildcard is necessary to catch them.
Thanks,
~kyle
As for the use of "LIKE", some of the zipcodes in the database are 9-digit, the wildcard is necessary to catch them.
Thanks,
~kyle
![]() |
Similar Threads
- Purpose of Pointers? (C++)
- Object Orientated C+++.net Calculator! (C++)
- pass the value to the text box (JavaScript / DHTML / AJAX)
- 98% done (C++)
- muliplying without using a * operator! (C++)
- Help with Pointer and While loop Please (C)
- String Problem (Visual Basic 4 / 5 / 6)
- silly Q...but i dont knw the answer !!! (VB.NET)
- C++ Syntax (C++)
Other Threads in the MySQL Forum
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database distinct drupal dui ec2 eliminate email enter enterprise error eudora facebook form foss gartner government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law license licensing linux maintenance managing mariadb micromanage microsoft microsoftexchange mindtouch montywidenius mozilla music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlquery mysqlsearch news open-xchange opendatabasealliance opensource operand oracle pdf php priceupdating query referencedesign remove reorderingcolumns results resultset saas search select sharepoint simpledb sourcecode sql statement sugarcrm syntax thunderbird transparency update





