daedalous Posted October 10, 2008 Share Posted October 10, 2008 SQL Server version: 5.0.51a Raw SQL, php var omitted: SELECT * FROM quote WHERE quote LIKE '%apple%' This code executes fine. 'quote' is the name of the table, in addition to being the name of a col in 'quote'. This really should be quite simple, and the above code executes without problem in phpmyAdmin, however, when used with this code: $result = mysql_query("SELECT * FROM quote WHERE quote LIKE '%$find%'"); if (@mysql_query($result)){ while($row = @mysql_fetch_array($result)){ echo $row['quote']; } It doesn't get past the if statement and gives me this: mySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1 I've echo'd the SQL query as a variable, with the php variable $find, and it prints correctly. It's a valid query. But I still get the syntax error above. Any ideas? Thanks in advance, Daed ps. I'm very new to php and mysql, my apologies if it's a simple mistake. Quote Link to comment https://forums.phpfreaks.com/topic/127820-solved-a-simple-search-query-is-broken/ Share on other sites More sharing options...
JasonLewis Posted October 10, 2008 Share Posted October 10, 2008 You are running a query, then running the queries result inside another query, which is why you are getting an error. $result contains a MySQL Resource ID, as you've seen. You need to remove the if() statement, or change it to if($result){. Quote Link to comment https://forums.phpfreaks.com/topic/127820-solved-a-simple-search-query-is-broken/#findComment-661731 Share on other sites More sharing options...
daedalous Posted October 10, 2008 Author Share Posted October 10, 2008 Egads, a simple mistake indeed... Thanks so much for your help, and sorry to have wasted anyones time. Quote Link to comment https://forums.phpfreaks.com/topic/127820-solved-a-simple-search-query-is-broken/#findComment-661735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.