How to do an IF statement based on the value of a MySQL table cell?

Posted by Susan on Stack Overflow See other posts from Stack Overflow or by Susan
Published on 2010-03-30T16:36:15Z Indexed on 2010/03/30 16:43 UTC
Read the original article Hit count: 389

Filed under:
|

How can I do an if statement based on the value of a mysql table cell. For example, I have a table of people with a column called marital_status. This column has one of two values: yes or no. But this doesn't work:

$query = mysql_query("SELECT marital_status FROM people WHERE first_name = 'John'");

while ($row = mysql_fetch_assoc($query)) {

     $maritalStatus = $row['marital_status'];

}

if ($maritalStatus == "yes") {
   echo "This person is married.";
}
else {
   echo "This person is NOT married.";
}

$maritalStatus == "yes" doesn't return as true even though that is exactly the value in that cell.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql