What's wrong with this search code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

What's wrong with this search code?

Post by jonas »

Code: Select all

$queryg = "SELECT * FROM games WHERE game_title LIKE '%'$game_search'%' ORDER BY `game_title` ASC";
	$mysql_stuff = mysql_query($queryg, $mysql_link);
	while($roc = mysql_fetch_row($mysql_stuff)){
		$gameID = $rocї0];
		$game_title = $rocї1];
		$system = $rocї2];
		print("<tr><td><div align="center">$system</div></td>");
		print("<td><div align="center"><a href="editagame.php?gameID=$gameID" target="main">$game_title</a></div></td></tr>");
	&#125;
I want this search to be really easy to use. If there are 10 games with Tom Clancy in the title and they search for 'tom' (no quotes) then it will bring any game with tom in the name.

This gives me an error like:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /usr/home/virtual/bolt3.com/webroot/htdocs/admin.bolt3.com/editagame-searchres.php on line 29

Thanks in advance.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try this instead.
$queryg = "SELECT game_title FROM games WHERE game_title LIKE '%$game_search%' ORDER BY game_title ASC";
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

Ok that fixes my error output but it doesn't display anything. I guess it assumes there are none but I can clearly see in my game database that there are 2 games with Tom in the title and I am searching under the string tom.

How do I make my search , well search for the terms 'tom' in the game_title table?

EDIT: Actually I typed the exact name in the search and it didn't pull it up either. So I guess something is wrong somewhere. :S
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Do an echo $queryg; and run the output/query directly in a mysql prompt (or phpMyAdmin etc) and see if it returns results. If it does then the problem is in the rest of the code, if it doesn't, then the query is at fault.
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

#1064 - You have an error in your SQL syntax near '$queryg = "SELECT game_title FROM games WHERE game_title LIKE '%$game_search%' O' at line 1
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Erm..no ;)
Do an echo $queryg; in your code, then use the output (whatever that echo shows in the browser) as the query in phpMyAdmin/mysql prompt .
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

I got it working! Thanks man!
Post Reply