Hy, I am working in codeigniter and I need to get multiple results on the same page. How I can do it.
Look at my code of Model, Controller and view.
Model:
function asia(){
$this->db->distinct();
$this->db->select();
$this->db->from('travels_detail t');
$this->db->join('all_destination a','t.destination = a.destination','inner');
$this->db->where('region', 'asia');
$this->db->group_by('t.destination');
$query= $this->db->get();
return $query->result_array();
}
controller:
function asia(){
$data['asia'] = $this->travel->asia();
$this->load->view('testing', $data);
}
view:
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<td> Departure </td> <td> Destination </td>
<td> Airline </td> <td> Fare </td>
<td> Type </td> <td> Via </td>
</tr>
<?php foreach($asia as $row){ ?>
<?php
echo '<tr>
<td> '.$row['departure'].' </td>
<td> '.$row['destination'].' </td>
<td> '.$row['airline'].' </td>
<td> '.$row['fare'].' </td>
<td> '.$row['type'].' </td>
<td> '.$row['via'].' </td>
</tr>';
}
?>
</table>
</body>
</html>
I get data of a continent "asia" from my database and display in a table. similarly i have to get some other data on the same page. Help me out please
function asia()
{
$data = [
'asia' => $this->travel->asia(),
// The fact that the controller method is named `asia`,
// does not restrict you to only call the asia() method
// on your model. Do whatever you want!
'europe' => $this->travel->europe()
];
$this->load->view('testing', $data);
}
Add another table to your view and iterate over the europe data.
Model:
function region($value){
$this->db->distinct();
$this->db->select();
$this->db->from('travels_detail t');
$this->db->join('all_destination a','t.destination = a.destination','inner');
$this->db->where('region', $value);
$this->db->group_by('t.destination');
$query= $this->db->get();
return $query->result_array();
}
controller:
function asia(){
$data['asia'] = $this->travel->region('asia');
$data['europe'] = $this->travel->region('europe')
$this->load->view('testing', $data);
}
just use $europe
way you have used $asia
in view