mysql - Use PHP to render multiple images to the browser -
the code below renders 1 images browser in conjunction database, want display of image of user, how should amend below code?
$coverpic = ""; $sql = "select filename photos user='$u'"; $query = mysqli_query($db_conx, $sql); if(mysqli_num_rows($query) > 0){ $row = mysqli_fetch_row($query); $filename = $row[0]; $coverpic = '<img src="user/'.$u.'/'.$filename.'" alt="pic">'; }
you use while loop in fetch results.
$coverpic = ''; $sql = "select filename photos 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="user/'.$u.'/'.$filename.'" alt="pic">'; //notice .= append string instead of overwrite } }
but if want make code little shorter less checks:
$coverpic = ''; $query = mysqli_query($db_conx, "select filename photos user='$u'")){ while($row = mysqli_fetch_row($query)) { $coverpic .= '<img src="user/'.$u.'/'.$row[0].'" alt="pic">'; }
Comments
Post a Comment