![]() |
mysqli - unable to use all results, even though the count shows 48 of them
For some reason I am unable to get all of the results in $getResults
In the code below I have commented what the output is for the lines that do output. The foreach($results as $result) { should be going through each of the 48 results, but only does one of them and stops. I can not figure out why it is missing the rest of them, even though the first output shows that there are 48 to do. Can anyone spot what I maybe doing wrong ? Code:
$getResults = db_query($mysqli, "SELECT `photos` FROM `items` WHERE `photos` != ''"); |
What version of PHP are you using? 5.4 is required if you intend to use Traversable on the mysqli_result (ie: the for each call).
|
I have PHP Version 5.3.20.
I have just looked at the original code I use to use for this when I used mysql and see that I should be using the assoc for each row. |
Yes, you can use a while loop, but not a foreach unless you upgrade to 5.4.
I wish they wouldn't change something like Traversable unless its in a major version; minor versions simply create confusion. Edit: Wait I'm wrong here. The foreach is already the results of a fetch_assoc call. I thought that was the result of the mysqli_result. In that case, you're simply missing your while loop. Looks to me that you'll likely have a normalization issue as well since I see you exploding on ||. |
Still the same, it only uses the first returned results.
The foreach does not advance to the next row. Code:
$getResults = db_query($mysqli, "SELECT `photos` FROM `items` WHERE `photos` != ''"); |
Read the edit I put up there, you're missing your while loop. You cannot loop a resultset using a foreach in 5.3 and mysqli_result.
I misunderstood the purpose of the foreach you have here. |
that did it, a few tweaks to the code later and it is not showing the other results.
I'll have to keep that in mind for now that I need to use WHILE for getting the next row of results. Thank you for your help. |
Mkay, so you got this working then or no?
|
yes, all working now. thanks again, and best of all it is less than half the code i started with after i had a rethink on the method i was using to locate missing images.
|
| All times are GMT +1. The time now is 11:27 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.