Page 1 of 1
What's wrong with this search code?
Posted: Thu Jun 03, 2004 8:04 pm
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>");
}
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.
Posted: Thu Jun 03, 2004 8:08 pm
by markl999
Try this instead.
$queryg = "SELECT game_title FROM games WHERE game_title LIKE '%$game_search%' ORDER BY game_title ASC";
Posted: Thu Jun 03, 2004 8:13 pm
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
Posted: Thu Jun 03, 2004 8:17 pm
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.
Posted: Thu Jun 03, 2004 8:21 pm
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
Posted: Thu Jun 03, 2004 8:26 pm
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 .
Posted: Thu Jun 03, 2004 8:42 pm
by jonas
I got it working! Thanks man!