[eluser]Bigil Michael[/eluser]
my table
Code:
id city state
1 tvm kerala
2 test1 kerala
3 kkkk Goa
4 chennai tamilnadu
i want the result like this
kerala
tvm
test1
goa
kkkk
tamilnadu
chennai
can anyone help me
my controller
Quote:$ho = $this->Hotels_model->test1();
$this->data['ho'] = $ho;
foreach($ho as $row)
{
$this->data['hot']= $this->Hotels_model->test2($row->state);
}
$this->load->view('hotels/list_all_hotels', $this->data);
model
Quote:function test1()
{
$this->db->distinct();
$this->db->select('state');
$this->db->from('hotels');
$result_product = $this->db->get();
return $result_product->result();
}
function test2($state)
{
$this->db->distinct();
$this->db->select('city');
$this->db->from('hotels');
$this->db->where('state',$state);
$result_product = $this->db->get();
return $result_product->result();
}
view
Quote:<?php
foreach ($ho as $row)
{ ?>
<div style="margin-top:8px; font-size:14px; font-weight:bold;"><?php echo $row->state;?> </div>
<?php
foreach ($hot as $lrow)
{
?>
<div><?php echo $lrow->city;?> </div>
<?php
}
?>
<?php
}
?>
now my result is
city is same for all states............
can anyone help me urgent
thanks in advance..