The problem I’m having is the second while loop only shows the last item from the result/db??
Can’t figure out what’s going on, can anybody spot what I’m doing wrong?
<ul class="gallery-portrait">
<li>Img name 1</li>
<li>Img name 2</li>
<li>Img name 3</li>
<li>Img name 4</li>
<li>Img name 5</li>
</ul>
<ul class="gallery-landscape">
<li>Img name 5</li>
</ul>
You cannot use the fetch() command multiple times. In your first loop you move through all results, so in the next loop it will not start with the first result.
Easiest way to solve this would be you do a fetchAll() into an array and then loop through the array
On the right track anyhow, I’ll report back once I figure what is happening.
It makes more sense now after you mentioned:
You cannot use the fetch() command multiple times. In your first loop you move through all results, so in the next loop it will not start with the first result.
I previously used bind_result: $stmt->bind_result($true, $id, $img_name, $ref, $layout, $collection);
These are now redundant?
I needed the $collection and $description (not shown) for the page title and metadata before I ran the loops - these are now empty?
Full script
if (isset($collection)) {
$stmt = $mysqli->prepare("
SELECT TRUE
, p.id
, p.img_name
, p.ref
, p.layout
, c.collection
FROM collection_photos p
LEFT JOIN collection_details c ON ( p.collection = c.collection )
WHERE c.collection = ?");
$stmt->bind_param('s', $collection);
$stmt->execute();
$stmt->bind_result($true, $id, $img_name, $ref, $layout, $collection);
//$stmt->store_result();
$resultSet = $stmt->get_result();
$data = $resultSet->fetch_all(MYSQLI_ASSOC);
$row_cnt = $resultSet->num_rows;
print $stmt->error; //to check errors
$stmt->fetch();