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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.