tr3gi Posted March 7, 2008 Share Posted March 7, 2008 Hi Here's my problem: I have a database full of staff members. My problem is that some of the staff members have for example medical training and others don't. When I'm creating the list I don't know how to display when the staffmember has medical training. Hope it makes sense.. Here's the lame code I'm an real beginner in PHP so the code might be totally wrong <?php $sql = "SELECT id, firstname, lastname, medic FROM staff"; $medic = "SELECT id, firstname, lastname, medic FROM staff where medic='1'"; $query = mysql_query($sql); $query_medic = mysql_query($medic); while($row = mysql_fetch_array($query)) { if ($query_medic) { echo "{$row['firstname']} {$row['lastname']}<img src=\"img/redcross.jpg\"><br />"; } else { echo "{$row['firstname']} {$row['lastname']}<br />"; } } ?> Can anyone help? thanks Quote Link to comment Share on other sites More sharing options...
moon 111 Posted March 7, 2008 Share Posted March 7, 2008 Please use code tags. <?php $sql = "SELECT id, firstname, lastname, medic FROM staff"; $medic = "SELECT id, firstname, lastname, medic FROM staff where medic='1'"; $query = mysql_query($sql); $query_medic = mysql_query($medic); while($row = mysql_fetch_array($query)) { if ($query_medic) { echo "{$row['firstname']} {$row['lastname']}<img src=\"img/redcross.jpg\">"; } else { echo "{$row['firstname']} {$row['lastname']}"; } } ?> THIS is the answer: <?php $sql = "SELECT id, firstname, lastname, medic FROM staff"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "{$row['firstname']} {$row['lastname']}"; if($row['medic'] != "" AND isset($row['medic'])) { echo "<img src=\"img/redcross.jpg\">"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.