Jump to content

[SOLVED][PHP / MYSQL] Trying to use SQL wildcard with variable


mada

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.