Scaryminds Posted March 3, 2011 Share Posted March 3, 2011 Am currently using this code, and actually thinking about it should split the query to an include in order to allow for other database drivers, on the chance we may decide to ditch the old MySQL. But I digress from the question. include($lib."dbconfig.php"); $q = 'SELECT * FROM file WHERE this = "'.$that'"; $result = mysql_query($q); if (mysql_num_rows($result) > 0) If the query doesn't pick up a row I'm getting this error yo, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\webpages\*\*\admin.php on line 553 So what would be a better way of testing if the query was successful? Link to comment https://forums.phpfreaks.com/topic/229457-better-way-to-determine-if-a-query-has-returned-at-least-one-row/ Share on other sites More sharing options...
kenrbnsn Posted March 3, 2011 Share Posted March 3, 2011 Your query has a syntax error in it, so the mysql_query() function is returning "false". Change the query to <?php $q = "SELECT * FROM file WHERE this = '$that'"; ?> and change the next line to <?php $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> at least while you're debugging your code. Ken Link to comment https://forums.phpfreaks.com/topic/229457-better-way-to-determine-if-a-query-has-returned-at-least-one-row/#findComment-1182219 Share on other sites More sharing options...
Scaryminds Posted March 3, 2011 Author Share Posted March 3, 2011 Hey thanks Ken, Did cut down the query as it was quite long and involved, but adding your die clause got the root issue Unknown column 'question' in 'where clause' d'uh! Been a while since I worked on the software and there are clearly some bugs we never got around to fixing Link to comment https://forums.phpfreaks.com/topic/229457-better-way-to-determine-if-a-query-has-returned-at-least-one-row/#findComment-1182224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.