So here is my php code:
$result = mysqli_query($con, "SELECT * FROM WW_temp");
$numrows = mysqli_num_rows($result);
if ($numrows!=0){
while ($row = mysqli_fetch_assoc($result) && $numOfPics >= 1){
$ImageFilename = $row["image"];
echo "$ImageFilename///";
$numOfPics--;
}
}
The output I am getting is ///////// (9 '/') when numOfPics is set to 3. There is definitely some fields in the column 'image' in the database. Is there anything wrong with the code?
You logic is squiffy. Currently your while condition is interpreted as:
$row = (mysqli_fetch_assoc($result) && $numOfPics >= 1)
So $row == true
while there are rows and $numOfPics >= 1
.
Change it to:
while ( ($row = mysqli_fetch_assoc($result)) && $numOfPics >= 1 ){
and it should behave sane-ly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.