0

Hello. I'm trying to use a wildcard for a $var. in a SELECT statement.
Can't seem to get it to work. '$search_Recordset2' is the $var.

("SELECT * FROM table WHERE col1 LIKE '$search_Recordset2' OR col2 LIKE '$search_Recordset2' OR col3 LIKE '$search_Recordset2'"

If I use '%$search_Recordset2%' or %'$search_Recordset2'%
I get error.

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by phpDave
0

Warning: sprintf() [function.sprintf]: Too few arguments in C:\xampp\htdocs\folder\search.php on line 62
Query was empty

1

Try this code and see what error you are getting.

<?
	echo $query= "SELECT * FROM table WHERE col1 LIKE '%$search_Recordset2%' OR col2 LIKE '%$search_Recordset2%' OR col3 LIKE '%$search_Recordset2%'";	
	$result = mysql_query($query);
	if (!$result) {
		die('Invalid query: ' . mysql_error());
	}

?>

Edited by vibhaJ: n/a

1

Are you using sprintf? If so it will look for the '%' to replace it.

1

Warning: sprintf() [function.sprintf]: Too few arguments in C:\xampp\htdocs\folder\search.php on line 62
Query was empty

Are you using a PHP framework? Or a custom database class?

Whats happening is that your SQL query is being run through sprintf() function, which will try and replace the special keys that start with the '%' signs with the variables passed in. See: http://php.net/sprintf

0

Thanks everyone, I tried this and it seemed to work ok.

1.
      ("SELECT * FROM table WHERE col1 LIKE '%%$search_Recordset2%%' OR col2 LIKE '%%$search_Recordset2%%' OR col3 LIKE '%%$search_Recordset2%%'"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.