• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
M.D array from model to view

#1
[eluser]Unknown[/eluser]
m returning array from model..and want to loop it in the view...here is my code...it works perfect in controller..and plz help me in passing same value to the VIEW

Code:
public function gets()
{
  
  $query="select name from cat";
  $query1=$this->db->query($query);
  
  
  foreach($query1->result_array() as $row)
  {
  
   $q="select * from post where cat=?";
   $q1=$this->db->query($q,$row['name']);
  
   $max[]=array(
   'a'=>$row['name'],
   'b'=> $q1->num_rows()
   );
  
  
  
  
  }
  
    
    return $max;
  
}


controller
Code:
public function login()
{
  
  print_r($tested=$this->Go->gets());
  
  $data['g']=$tested;
  
  
  //this code works 5n
  foreach($tested as $test)
  {
   echo $test['a'];
   echo $test['b'];
  
  }
  
  $this->load->view('login',$data);
}

view:
Code:
foreach($g as $h);
{

//doesnt loop all the values only last value
echo $h['a'];
echo $h['b'];
}

thanks

#2
[eluser]InsiteFX[/eluser]
Maybe take the ; off the end of the foreach loop in your view.

Code:
<?php foreach ($g as $h): ?>
    <?php echo $g; ?>
    <?php echo $h; ?>
<?php endforeach; ?>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.