Select ... Where ... Like

A

Anonymous

Guest
Your first query looks correct. You've tried it from the MySQL console?

The second query is missing quotes around the LIKE match string.

Code:
<?
$query = "SELECT * FROM amglossary WHERE terms LIKE '" . $colTerm_Recordset1 . "%'";
?>
 
JWP said:
$query_Recordset1 = sprintf("SELECT * FROM amglossary WHERE terms LIKE 'A%'");

and it still says:
Warning: sprintf(): too few arguments

It would have been really useful to know that you were using sprintf() in the first place, as I can't imagine how we would have solved this problem without that crucial bit of knowledge.

Part of the solution is to not use sprintf() where you oughtn't. There's no reason to be using sprintf() in this context, as you obviously aren't doing any special formatting, and in fact this is one of the Top 21 PHP Programming Mistakes. Is there some PHP tutorial or book out there that's teaching people to use sprintf() instead of plain old string parsing or concatenation?

Your code works fine without the sprintf():

Code:
$query_Recordset1 = "SELECT * FROM amglossary WHERE terms LIKE 'A%'";

If you really want to know why your sprintf() wasn't working (so long as you promise never to use it again unless you actually need a formatted string), I'll refer to the documentation.
 
Back
Top