I have been tasked with presenting a list of all photographs in relation to a photographer, when that photographer is clicked. I need to echo the list of photographs but currently, only the last row is being echoed.
The rows returned should look like this (minus the bullet points):
1 Amager Standpark Sunset 2010-07-01 _img/1/1.jpg 1
1 Field Landscape 2010-07-09 _img/1/2.jpg 1
However my code is only returning this:
1 Field Landscape 2010-07-09 _img/1/2.jpg 1
Below is my code:
// SQL query to get all photo data from specific photographer
$query = mysqli_query($con, "SELECT * FROM Photograph WHERE PhotographerId='$photographerID'");
$photos = mysqli_fetch_assoc($query);
$num = mysqli_num_rows($query);
if ($num == 0) {
echo 'This are no photographs present for this photographer.';
} else if ($num > 0) {
$list = '';
while ($photos = mysqli_fetch_array($query)) {
$list .= $photos['PhotographerId'] . ' ' . $photos['PhotographName'] . ' ' .
$photos['Date'] . ' ' . $photos['PhotographURL'] . ' ' .
$photos['Visible'] . ' </br>';
}
echo $list;
}
mysqli_fetch_assoc($query);fetches the first row, thenmysqli_fetch_array($query)fetches the subsequent rows within the loop. But you never use the first result set for anything. Also, make up your mind which kind of array you want!