php - array_combine and associative result -


i using yii framework

$job_status = yii::app()->db->createcommand()             ->select('count(*) total_count, image_status')             ->from('alldetail')             ->where("jobid=:job_id",array(':job_id'=>$job_id))             ->group('image_status')             ->queryall(); $status_key = array(); $images = array(); foreach($job_status $job){     $imgstate = array_push($status_key,compclass::statusmaster($job['image_status']));     $tot_img = array_push($images,$job['total_count']); } 

status master refers function in component class

which has

public static function statusmaster($status_code) {     switch($status_code)     {         case 0:         $alias = 'queue';         break;             case 1:         $alias = 'processing';         break;             case 2:         $alias = 'completed';         break;      }             return $alias;         } 

here view

<strong>queued: <?php echo $job_status['queue']; ?></strong><br /> <strong>processing: <?php echo $job_status['processing']; ?></strong><br /> <strong>completed: <?php echo $job_status['completed']; ?></strong><br /> 

the above script throws error if doesn't have status_code (i.e)

if image in database has status_code 0 , 1 but not 2 getting undefined index completed. instead should show 0.

whether can use exception handling of other efficient method

set value each 'image_status' in query, saves make call "statusmaster($status_code)" function. have correct value in $job object inside of foreach($job_status).

$job_status = yii::app()->db->createcommand()             ->select('count(*) total_count, case image_status                                                     when 0 "queue"                                                     when 1 "processing"                                                     when 2 "completed"                                                     else "defoult value"                                                     end image_status ')             ->from('alldetail')             ->where("jobid=:job_id",array(':job_id'=>$job_id))             ->group('image_status')             ->queryall(); 

in view:

<strong>queued: <?php echo isset($job_status['queue'])?  $job_status['queue'] : ''; ?></strong><br /> <strong>processing: <?php isset($job_status['processing'])?  $job_status['processing'] : ''; ?></strong><br /> <strong>completed: <?php isset($job_status['completed'])?  $job_status['completed'] : '';?></strong><br /> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -