i want to show 2 tables that contain diffent information in a single codeigniter view page
heres the code on model.php (they are in the same class
> public function showPlants(){
> return $this->db->get('plantsdata');
> }
>
> public function showAnimals(){
> return $this->db->get('animalsdata');
> }
the code on controller.php
> public function plantsandanimals() {
> $data = [
> 'finaldata'=>$this->db->showPlants()->result()
> ];
> $data = [
> 'finaldata'=>$this->db->showAnimals()->result()
> ];
> $this->load->view('viewplantsandanimal',$data);
> }
and then the viewplantsandanimals.php
<table>
<?php foreach ($finaldata as $here) { ?>
<tr>
<td> <?= $here->animalsname
</td>
<?php }; ?>
<tr>
</table>
<table>
<?php foreach ($finaldata as $here) { ?>
<tr>
<td> <?= $here->plantsname
</td>
<?php }; ?>
<tr>
</table>
that so i can have two tables to show animals and plants. but every tutorial on google either
You're very close and I'm hoping I'm not helping you cheat !! But you can include different names in the array and then call the different names on the view page. Something like this:
public function plantsandanimals() {
$data = [
'plants'=>$this->db->showPlants()->result(),
'animals'=>$this->db->showAnimals()->result()
];
$this->load->view('viewplantsandanimal',$data);
}
foreach ($plants as $here) OR foreach ($animals as $here)