Jump to content

2 rows 'found', but only data for 1 row returned


stubarny

Recommended Posts

Hello,

 

This is confusing me! - this code is finding 2 rows of data ($nrows is 2), but I'm only getting 1 row of data returned. On the second while loop I'm getting the following error message:

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/website.com/test.php on line 26

				$query ="SELECT * FROM Accounts WHERE (jaaLatitude = '' OR jaaLongitude = '')";	
				$result=mysql_query($query)  
					or die ("Connection to database table failed."  . mysql_error());
				$nrows=mysql_num_rows($result);

				$i = 0;
				if ($nrows > 0)
				{	
					while($record = mysql_fetch_array($result, MYSQL_BOTH))
						{	
							$jaaIndex = $record[jaaIndex];	
							$jaaEmail = $record[jaaEmail];
							$jaaLocation = $record[jaaLocation];
							$jaaLongitude = $record[jaaLongitude];
							$jaaLatitude = $record[jaaLatitude];

                                                        echo "<br>test jaaEmail is $jaaEmail<br>";

                                                        $i = $i + 1; 
                                                 }
                                 }

As I say the first while loop is working, so I don't see what can be wrong with the qurery (it's not failing).

 

Thanks for your help,

 

S

Link to comment
Share on other sites

You have a bunch of errors in your code.

 

1) Your "or die()" error message relates to a database connection failing, if mysql_query returns false it has nothing to do with your connection here.

2) mysql_* has been deprecated and should no longer be used.

3) Numeric string need to be quoted in php. eg; $record[jaaIndex] should be $record['jaaIndex']

 

Now as for your issue. Have you taken any notice at all of the warning that is being produced? What does is the value of $result?

Link to comment
Share on other sites

That is indeed normal, so that warning is not related at all to the code you have posted.

 

The code you have posted also cannot possibly only iterate once if $nrows is 2. How can you be certain $nrows is equal to 2 ?

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.