I have a MySQL database that holds a list of classes in columns, and each class has a "level" which is the value of the row, which changes for each person. So, math, for example, has 0, 1, 2, and 3 as possible values, 0 being not selected as a class, and 1, 2, and 3 being high, medium, and low, respectively.
I have a MySQL query which pulls just the classes from a user's database row.
$result = mysql_query("SELECT math, physics, biology, chemistry, english, spanish, history, economics, art, theoryofknowledge, extendedessay FROM users WHERE username = '". $login_session ."'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
echo "Math:". $row['math'] ."<br />";
echo "Physics:". $row['physics'] ."<br />";
echo "Biology:". $row['biology'] ."<br />";
echo "Chemistry:". $row['chemistry'] ."<br />";
echo "English:". $row['english'] ."<br />";
echo "Spanish:". $row['spanish'] ."<br />";
echo "History:". $row['history'] ."<br />";
echo "Economics:". $row['economics'] ."<br />";
echo "Art:". $row['art'] ."<br />";
echo "Theory of Knowledge:". $row['theoryofknowledge'] ."<br />";
echo "Extended Essay:". $row['extendedessay'];
}
Here is the output for a user:
Math:1
Physics:1
Biology:0
Chemistry:2
English:2
Spanish:3
History:0
Economics:1
Art:0
Theory of Knowledge:1
Extended Essay:1
How could I determine which level a user has, without doing an if statement for every single time the class is called? I need to call the classes in multiple places on the site, and I'd like an easy way to check which classes, and level, the user has.
Thanks!