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

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?

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.