0
votes
class index_model extends CI_Model {

public function get_data()
{       

    $query = $this->db->query('SELECT * FROM sgrn_tblrecipe_addnew ORDER BY POPULARITY DESC LIMIT 4');
    $result=$query->result();
      foreach($result as $row)
      {

            $variable=$row->RECIPE_ID;
            $this->myOtherFunction($variable);
      }
    return $result;
}
function myOtherFunction($variable) 
{

       $query = $this->db->query('SELECT * FROM sgrn_tblrcp_user_like WHERE RECIPE_ID="'.$variable.'"');
       $result =$query->num_rows();
       echo $result;                     
       return $result;  
}
}

Hi I try this code developed by me for accessing different table data in different variable,but i have one problem that it doesn't give the result of second query.

Actually i use call by function technique by passing variable as parameter...if any other method is available then suggest me...

I have to use multiple select queries in MODEL for fetching data from database by different table but after getting first query result by these ID i have to use in second query WHERE clause that gives different result from different table.... and these two results access on VIEW as different data to view

2
If I understand correctly, you want your last 4 tblrecipe_addnew and for each one the number of user_like it have. Am I right ? - AdrienXL
yes, but i want two results saperate i.e from tblrecipe_addnew and tblrcp_user_like.But tblrcp_user_like table result depend on tblrecipe_addnew table row ID... - Nilesh Yadav

2 Answers

0
votes

you can achieve same result by structuring your code like below example

$this->db->select('*');
            $this->db->from('R_dropzones');
            $query = $this->db->get();
            $dropzone_list = $query->result();

    if(!empty($dropzone_list))
    {
        $count=0;
        $j=0;
        foreach ($dropzone_list as $k=>$v)
        {
            /* Count Dropzone Qty */
            $this->db->select('u_drop_zone');
            $this->db->from('R_units');
            $this->db->where(array('u_status'=>'DZ','u_drop_zone'=>$v->dz_id));
            $unit_query = $this->db->get();
            $unit_count = $unit_query->num_rows();

            if( $unit_count > 0 )   
            {   
                $this->msg['Dropzone'][$j]['dz_qty']=$unit_count;
                $this->msg['Dropzone'][$j]['dz_id']=$v->dz_id;
                $this->msg['Dropzone'][$j]['dz_desc']=$v->dz_desc;
                $this->msg['Dropzone'][$j]['dz_barcode']=$v->dz_barcode;
                $j++;
                $count++;
            }   
        }

    }
0
votes

you can use $this->template->render(); function to get your data value in desire template

$this->template->set_template('template_name');
$data['content'] = $result;
$this->template->write_view('content', $data);    
$this->template->render();