Jump to content

mysql_num_rows returns 1 but mysql_fetch_assoc returns null?


homer_3
Go to solution Solved by kicken,

Recommended Posts

I'm using sql with php and mysql_fetch_assoc is returning null even though mysql_num_rows returns 1. I've echoed the query statement I'm using and entered the output manually and sql does return a value. I'm not sure why the code is returning a null. Basically I have

$rv = mysql_query("SELECT (blah) from my_table WHERE my_key = " . $value . ";", $mysql_link);
echo "" . mysql_num_rows($rv);
if(!$rv)
{
	echo 'There was a problem with your order. '; 
	die('Could not connect: ' . mysql_error($mysql_link));
}else
{
	if ($row = mysql_fetch_assoc($sql))
	{
		//code
	}else
	{
		echo 'There was a problem setting up your order. '; 
		die('Missing fields: ' . mysql_error($mysql_link));
	}
}

And the missing fields is printing out even though echo "" . mysql_num_rows($rv); shows 1.

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.