0

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?

2
  • 2
    Try with echo "{$ImageFilename}///"; ? Commented Feb 25, 2014 at 21:53
  • try to dump your row to see what's in it (var_dump($row)); this should help you (and us) figure out what's wrong. Maybe also add a sample of the WW_temp table so we can get a better idea. Commented Feb 25, 2014 at 21:58

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.