stubarny Posted July 6, 2014 Share Posted July 6, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/289497-2-rows-found-but-only-data-for-1-row-returned/ Share on other sites More sharing options...
trq Posted July 6, 2014 Share Posted July 6, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/289497-2-rows-found-but-only-data-for-1-row-returned/#findComment-1484052 Share on other sites More sharing options...
stubarny Posted July 6, 2014 Author Share Posted July 6, 2014 $result returns "Resource id #5" if I use echo or print_r, which i think is normal? Quote Link to comment https://forums.phpfreaks.com/topic/289497-2-rows-found-but-only-data-for-1-row-returned/#findComment-1484056 Share on other sites More sharing options...
trq Posted July 7, 2014 Share Posted July 7, 2014 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/289497-2-rows-found-but-only-data-for-1-row-returned/#findComment-1484058 Share on other sites More sharing options...
davidannis Posted July 7, 2014 Share Posted July 7, 2014 Is the code you show in a bigger loop? The error message says line 26 but it is about 8 lines in. Quote Link to comment https://forums.phpfreaks.com/topic/289497-2-rows-found-but-only-data-for-1-row-returned/#findComment-1484063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.