RIRedinPA Posted November 22, 2010 Share Posted November 22, 2010 I have a class that I use to do my db queries. I'm starting to work on a new project and purposely put in a query which would fail, thus returning no results, just to make sure the error trapping is working. Here's my code: function getResults($query) { $results = mysql_query($query) or die (mysql_error() . "\n\nYour request couldn't be procesed.<p>" . $query); $itemcount = count($results); if ($itemcount > 0) { $i=0; while($itemcount > $i) { $i++; $userdata = array('queryresult' => '!success', 'displayName' => mysql_result($results, $i-1, 'displayName'), 'title' => mysql_result($results, $i-1, 'title')); } } else { $userdata = array('queryresult' => '!fail'); } return $userdata; } when I print $itemcount it returns a value of 1, which forces the conditional and an attempt at parsing the results array. However, in my browser I get these error messages: 1 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in /Library/WebServer/Dev/timesheet/lib/mysqlconnect.php on line 29 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in /Library/WebServer/Dev/timesheet/lib/mysqlconnect.php on line 29 It seems as if it is telling me that results has both 1 and no items. Am I doing something to cause this? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 count($results) will return 1 because $results holds the result resource, not the number of records the query returned. Quote Link to comment 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.