robertlob Posted May 29, 2014 Share Posted May 29, 2014 The following snippit should retrieve 10 images stored in an SQLite database table. But for some reason that mystifies me, it only retrieves 9. (Or one less than the number of images that are actually stored on the table): ___________ # retrieve photos for this property $query = "SELECT * FROM binary_data where propID = $prop_id"; $result = $db->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); # save each image data to file foreach($result as $row) { $filename = $row['filename']; $image = $row['bin_data']; file_put_contents($filename, $image); } ?> _____________ It saves the ones it gets to the temporary files as it should, and they appear on the webpage as they should. But one is always missing. Any suggestions/corrections appreciated. -Robert Quote Link to comment Share on other sites More sharing options...
Solution robertlob Posted May 29, 2014 Author Solution Share Posted May 29, 2014 I found a working solution: Removed this line from my code... $row = $result->fetch(PDO::FETCH_ASSOC); and it seems to solve the problem. The is a similar Q in the FAQ section, although it regards mySQL instead of SQLite. "The function returns the next row in the result set and advances the internal pointer. So before your loop runs, you're already pointing at the second row in the result set." Removing that line allows it to start at the first row." -Robert Quote Link to comment 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.