scarface83 Posted March 23, 2007 Share Posted March 23, 2007 Hi, can you use a switch statement with mysql and how would i do it with the following ? require ('db_connect.inc'); $query ="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' GROUP BY abs_value "; while ($row = mysql_fetch_array($run)) { if ($row['abs_value'] == 1) { $late_num = $row; }elseif ($row['abs_value'] == 2) { $sick_num = $row; }elseif ($row['abs_value'] == 3) { $sickhf_num =$row; }elseif ($row['abs_value'] == 4) { $awol_num =$row; } } Thanks Link to comment https://forums.phpfreaks.com/topic/43960-sql-with-a-switch-statement/ Share on other sites More sharing options...
obsidian Posted March 23, 2007 Share Posted March 23, 2007 I believe this is what you're after: <?php switch ($row['abs_value']) { case 1: $late_num = $row; break; case 2: $sick_num = $row; break; case 3: $sickhf_num =$row; break; case 4: $awol_num =$row; break; } ?> Link to comment https://forums.phpfreaks.com/topic/43960-sql-with-a-switch-statement/#findComment-213410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.