0

I am trying to show different image if the other is empty but the below code isn't working for me. In this case I have empty row for image two and image three has image name.

What am I missing here?

    $stmt = $mydb->prepare("select * from images where username = ? order by id desc");
echo $mydb->error;
$stmt->bind_param('s', $username->username);
$stmt->execute();
$result = $stmt->get_result();
?>
<?php while ($row = $result->fetch_assoc()) {
if($row['image_two'] = '')
{
echo $row['image_three'];
}
}?>
3
  • please think about accepting a answer so the thread closes. Thanks! Commented Nov 10, 2013 at 1:11
  • @CristianCavalli Okay I did, as it always tells me to wait I then forget. Commented Nov 10, 2013 at 1:13
  • remember to be careful with loose comparisons (i.e. '==') Strict comparisons like '===' are generally better, although when dealing with what php considers to be null or empty use of the empty() function is generally more reliable. Commented Nov 10, 2013 at 1:16

2 Answers 2

3

you should do it with the native PHP functions

if(empty($row['image_two']))

Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

The following things are considered to be empty:

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • $var; (a variable declared, but without a value)
Sign up to request clarification or add additional context in comments.

Comments

1

You need to use double equals for comparison.

if($row['image_two'] == '')

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.