3raser Posted July 26, 2010 Share Posted July 26, 2010 PHP Code: if($revision_p=="317") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='317'"); } elseif($revision_p=="474") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='474'"); } elseif($revision_p=="508") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='508'"); } elseif($revision_p=="525") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='525'"); } elseif($revision_p=="530") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='530'"); } elseif($revision_p=="562") { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='562'"); } else { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%'"); } if(mysql_num_rows($search_query) > 0) { $amount = mysql_num_rows($search_query); echo "A total of ". $amount ." results have been found: <br/><br/>"; while($row = mysql_fetch_assoc($search_query)) { echo "<b><span style='color:red'>[". $row['revision'] ."]</span></b> Title: <b>". $row['title'] ."</b> Date: <b>". $row['date'] ."</b> <a href='view.php?id=". $row['id'] ."'><b>View</b></a><br/><br/>"; } } Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9796960/public_html/snippets.php on line 100 I've already checked for reserved words. Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/ Share on other sites More sharing options...
tomtimms Posted July 26, 2010 Share Posted July 26, 2010 what happens when you echo out $search_query? Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091421 Share on other sites More sharing options...
tomtimms Posted July 26, 2010 Share Posted July 26, 2010 also looks like `revision` needs to be just revision....your query isn't correct. Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091422 Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2010 Share Posted July 26, 2010 You have got two WHERE clauses in your queries. You can only have one. I suspect you wanted to form a logical expression using the AND keyword. Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091423 Share on other sites More sharing options...
3raser Posted July 26, 2010 Author Share Posted July 26, 2010 what happens when you echo out $search_query? Well, when I just did the regular query, where it says else - I get this Resource id #6 Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091424 Share on other sites More sharing options...
3raser Posted July 26, 2010 Author Share Posted July 26, 2010 You have got two WHERE clauses in your queries. You can only have one. I suspect you wanted to form a logical expression using the AND keyword. Oh. Hell, I don't know why I didn't see the first WHERE in there. Thank you. Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091425 Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2010 Share Posted July 26, 2010 Also, why are you writing out all of that repetitious code where only the value is different and you have to write out more code to add another value? Just use an array - $revisions = array(); $revisions[] = "317"; $revisions[] = "474"; $revisions[] = "508"; $revisions[] = "525"; $revisions[] = "530"; $revisions[] = "562"; if(in_array($revision_p,$revisions)){ $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' AND `revision`='$revision_p'"); } else { $search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%'"); } Link to comment https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.