Welcome Guest, Not a member yet? Register   Sign In
order_by problem
#1

[eluser]Bigil Michael[/eluser]
can anyone help me????
i want to get the result in a alphabetical order

Quote:function select_all_state($limit, $pgoffset)
{

$this->db->order_by("state.state_name");

$this->db->select('state.state_name');

$this->db->from('state');
$this->db->join('location', 'location.state_id = state.state_id');
$result_product = $this->db->get();
return $this->db->get('state')->result_array();
}
here order_by not working
can anyone help me??????
urgent.....
thanks in advance
#2

[eluser]Bigil Michael[/eluser]
can anyone help me?????
thanks in advance
#3

[eluser]toopay[/eluser]
should be like...
Code:
...
function select_all_state($limit, $pgoffset)
{
      $this->db->select('state.state_name');
      $this->db->from('state');
      $this->db->join('location', 'location.state_id = state.state_id');
      $this->db->order_by('state.state_name','asc');
      $this->db->limit($limit, $pgoffset);
      $query = $this->db->get();
      return $query->result_array();
}
...
#4

[eluser]Bigil Michael[/eluser]
now it shows error

anyway thanks for your reply

my full code is

controller
Quote:function availabe_hotels($pgoffset='')
{
$config['per_page'] = 10;
$config['total_rows'] = $this->Hotels_model->get_total();
$config['base_url'] = site_url().'/fleets/index/';
$config['uri_segment'] = 3;
$this->data['count_no'] = ($this->uri->segment(3)=='')? 0 : $this->uri->segment(3);
$build_array = array();
$fleets = $this->Hotels_model->select_all_state($config['per_page'], $pgoffset);

foreach($fleets as $row){
$build_array[] = array (
'fleets_array' => $row,
'listefleets_array' => $this->Hotels_model->list_all_state($row['state_id'])
);
}
$this->data = array (
'meow' => $build_array
);
$this->data['pgoffset'] = $pgoffset;
$this->pagination->initialize($config);
$this->data['pagetitle'] = 'Hotels';
$this->load->view('hotels/list_all_hotels', $this->data);
}

model
Quote:function select_all_state($limit, $pgoffset)
{
$this->db->limit($limit, $pgoffset);
$this->db->order_by('state_name');
$this->db->select('state.state_name');
$this->db->from('state');
$this->db->join('location', 'location.state_id = state.state_id');
$result_product = $this->db->get();
return $this->db->get('state')->result_array();
}

function list_all_state($cid)
{
$this->db->where('state_id',$cid);
$result_product = $this->db->get('location');
return $result_product->result_array();
}

view

Quote:<?php
foreach ($meow as $crow)
{ ?>
<ul id="t2">
<div style="padding-bottom:10px; font-size:14px;">&lt;?php echo $crow['fleets_array']['state_name'];?&gt; </div>

&lt;?php
foreach ($crow['listefleets_array'] as $lrow)
{
?&gt;
<li><a style="color:#8F8F8F;" href="&lt;?php echo site_url().'/hotels/list_hotel/'.$lrow['location_name'];?&gt;" title="Hotels, Villas and serviced apartments in &lt;?php echo $lrow['location_name'];?&gt;">&lt;?php echo $lrow['location_name'];?&gt;</a> </li>
&lt;?php
}
?&gt;
</ul>
&lt;?php
}
?&gt;

my aim is to print state and city like this

state name statename
city1 city 1
city2 city 2
city3

now the code is working but limit and order_by is notworking

can u help me thanks in advace
#5

[eluser]toopay[/eluser]
What you mean about "now it shows error". There will be no errors! Are you mean warning? Maybe, if you dont give some predefined value to them(var $limit and $pgoffset at your model) and no params passing to your model. Fix it by...
Code:
function select_all_state($limit=NULL, $pgoffset=NULL)
Your previously (or recent) model clearly wrong, look at them at this section :
Code:
...
      $result_product = $this->db->get();

      // In this line why you dont use $result_product->result_array() instead generating other queries?
      // In above line, you generating a query to $result_product, for what?
      return $this->db->get(‘state’)->result_array();
}
....
#6

[eluser]toopay[/eluser]
I re-ordering your model lines, just for more intuitive feels, its more make sense (and more easy to read) for us(especially me), by ordering '$this->db->' statement to 'select', 'from', 'join', 'order_by', 'limit' than what you have in your model right now.

But it just my suggestion (which means MY CODING STANDARD), you can take it or stay with yours, that will be no problems.
#7

[eluser]Bigil Michael[/eluser]
this is the error message
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined index: state_id

Filename: controllers/hotels.php

Line Number: 143
#8

[eluser]Bigil Michael[/eluser]
i want the order_by only

remaining portions are working well
#9

[eluser]toopay[/eluser]
OF COURSE! Thats because you select only 'state_name' from 'state' table, but you try to get 'state_id' at this line of your controller :
Code:
...
foreach($fleets as $row){
....
// This is you do something wrong! There are no 'state_id' in $row variable!
‘listefleets_array’ => $this->Hotels_model->list_all_state($row[‘state_id’])
...

You can fix it by change your model to
Code:
$this->db->select('state.state_name,state.state_id');
#10

[eluser]toopay[/eluser]
Code:
$result_product = $this->db->get();
      return $this->db->get(‘state’)->result_array();
above code 'not well' at all.




Theme © iAndrew 2016 - Forum software by © MyBB