[Solved] Use PHP to render multiple images to the browser [closed]


You use a while loop in to fetch the results.

$coverpic="";
$sql = "SELECT filename FROM photos WHERE user="$u"";
$query = mysqli_query($db_conx, $sql);
if(mysqli_num_rows($query) > 0){

   while($row = mysqli_fetch_row($query)) {
      $filename = $row[0];
      $coverpic .= '<img src="https://stackoverflow.com/questions/16442747/user/".$u."https://stackoverflow.com/".$filename.'" alt="pic">'; //notice the .= to append to the string instead of overwrite
   }

}

But if you want to make your code a little shorter with less checks:

$coverpic="";
$query = mysqli_query($db_conx, "SELECT filename FROM photos WHERE user="$u"")){
while($row = mysqli_fetch_row($query)) {
   $coverpic .= '<img src="https://stackoverflow.com/questions/16442747/user/".$u."https://stackoverflow.com/".$row[0].'" alt="pic">';
}

8

solved Use PHP to render multiple images to the browser [closed]