mada Posted January 18, 2007 Share Posted January 18, 2007 I am trying to call everything from a table dependent on the first letter of the "name" field.[code] $sql = mysql_query('SELECT * FROM test1 WHERE name LIKE "A%" ORDER BY Name') or die(mysql_error());[/code]works absolutely fine when I attempt to call all rows where the name begins with A.However I am trying to replace A with a variable. i.e:-[code] $letter = "A"; $sql = mysql_query('SELECT * FROM test1 WHERE name LIKE "$letter%" ORDER BY Name') or die(mysql_error());[/code]But this fails to display anything. How can I resolve this? Link to comment https://forums.phpfreaks.com/topic/34719-solvedphp-mysql-trying-to-use-sql-wildcard-with-variable/ Share on other sites More sharing options...
trq Posted January 18, 2007 Share Posted January 18, 2007 Variables are not interpolated when within single quotes, use....[code=php:0]$sql = mysql_query("SELECT * FROM test1 WHERE name LIKE '$letter%' ORDER BY Name") or die(mysq_error());[/code] Link to comment https://forums.phpfreaks.com/topic/34719-solvedphp-mysql-trying-to-use-sql-wildcard-with-variable/#findComment-163617 Share on other sites More sharing options...
mada Posted January 18, 2007 Author Share Posted January 18, 2007 Excellent, that worked perfectly.Thankyou!!!! Link to comment https://forums.phpfreaks.com/topic/34719-solvedphp-mysql-trying-to-use-sql-wildcard-with-variable/#findComment-163638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.