Jump to content

Item count at 1 when no items being returned


RIRedinPA

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.