Jump to content

SQL with a Switch Statement ?


scarface83

Recommended Posts

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

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;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.