Cooper Cooper - 5 months ago 31
SQL Question

If row status is 1 output approved on the view using CodeIgniter

I want to output the statement you are APPROVED if table row column status is 1.
Am able to output data from the database. Now i want to output the statement only.

My controller

public function index(){

$this->load->database();
$this->load->model('Truckeraccount_model');
$data['account_details']=$this->Truckeraccount_model->account_details();
$this->load->view('header');
$this->load->view('truckers/truckeraccount_view', $data);
$this->load->view('footer');

}


My Model

public function account_details() {

$this->db->select('*');
$this->db->from('trucker');
$query = $this->db->get('trucker');
return $query;

}


My View

<?php
foreach ($account_details->result() as $row)
{
?>
Area - <?php echo $row->area;?><br>
Mobile Number - <?php echo $row->phone_number;?><br>
Address - <?php echo $row->address;?><br>
Email Address - <?php echo $row->email_address;?><br>
Status - <?php echo $row->status;?><br>

<?php } ?>

Answer

use if statement like this,

<?php
    foreach ($account_details->result() as $row)  
     {
     ?>   
        Area - <?php  echo $row->area;?><br>
        Mobile Number - <?php  echo $row->phone_number;?><br>
        Address - <?php  echo $row->address;?><br>
        Email Address - <?php  echo $row->email_address;?><br>
        Status - <?php  if($row->status == 1) { echo 'you are Approved'; }?><br>

    <?php } ?>