Checking if column value == TRUE in php and mysql
I'm trying to create a menu that will only populate links based on what
the user has subscribed to. Basically I will be using php to check the
user against a table that will contain his/her email + registered courses
in a boolean format ie:
email | course 1 | course 2 | course 3|
john@email.com TRUE FALSE TRUE
I want to create an if statement that if course 1 = true WHERE email =
john@email.com then echo some html
else check for course 2, etc.
What I'm having trouble with is how would i structure my if statement?
Would I use
$sql="Select * FROM courses WHERE user = $user and course1 = TRUE"
$result = mysql_query($sql) or mysql_die($sql)
if($result)
{
echo html
}
or is there another way to do this? Is there a way I can write an if
statement to check multiple values for example if($_SESSION['auth_id'] ==
1) and if (course1 == TRUE) (i know that the last if statement isnt
correct but I'd like to combine the two if possible). Would I need to
write it as an if statement within an if statement:
if ($something)
{
if ($somethingelse)
{
do work
}
}
or an elseif:
if ($something)
{
elseif ($somethingelse)
{
do work
}
}
No comments:
Post a Comment