• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Group according to a field problem...!!!

#1
[eluser]Roy MJ[/eluser]
Can anyone tell me if its possible to group together values from a table according to a particular field.

I am having five values in the table : id,name,district,workstation,state.

My requirement is to group together all table entries accordong to state. It should be like this.

Andra Pradesh




S.No Name District Work Station State

1 Ramesh paul Warangal Warangal

2 Suresh Paul Warangal Nizanpalli

3 Battinini Sujatha Warangal Nizanpalli

4 Shalem Raju Rangareddy Vikarabadh

5 M.Shiromani Rangareddy Vikarabad

6 B.Prakash babu Warangal Gundrathimadugu

7 Bandi Pushpalatha Warangal Gundrathimadugu

8 Emmady Suresh Warangal Palakurthy

9 E.Sujatha Warangal Palakurthy

10 Arun Kumar Warangal Wardhanapet



Kerala



S.No Name District Work Station State

1 Ramesh paul Warangal Warangal

2 Suresh Paul Warangal Nizanpalli

3 Battinini Sujatha Warangal Nizanpalli

4 Shalem Raju Rangareddy Vikarabadh

5 M.Shiromani Rangareddy Vikarabad

6 B.Prakash babu Warangal Gundrathimadugu

7 Bandi Pushpalatha Warangal Gundrathimadugu

8 Emmady Suresh Warangal Palakurthy

9 E.Sujatha Warangal Palakurthy

10 Arun Kumar Warangal Wardhanapet




where AndraPradesh, Kerala comes under the states. Can anyone tell me how to write the code so that it displays the state field once and all table entries having the particular state will be listed, then next state and corresponding entries and so on. Please help.

My controller is as follows:

Code:
function index($pgoffset='')
    {
        //$this->data['service'] = $this->Services_model->select_services();
        $this->data['pagetitle'] ='Listmissionaries';
        $config['per_page'] = 20;
        $config['total_rows'] = $this->Listmissionaries_model->get_total();
        $config['base_url'] = site_url().'/listmissionaries/index/';
        $config['uri_segment'] = 3;
        $this->data['listmissionaries'] = $this->Listmissionaries_model->select_listmissionaries($config['per_page'], $pgoffset);
        $this->data['pgoffset'] = $pgoffset;
        $this->pagination->initialize($config);
        $this->load->view('listmissionaries', $this->data);
    }

My model is as follows:

Code:
function get_total()
    {
        $count=0;
        $this->db->select('COUNT(id) AS total');
        $this->db->from('listmissionaries');
        $this->db->order_by('id','asc');
        $this->db->where('status','1');
        $result_total = $this->db->get();
        if($result_total->num_rows()>0){
            $row    = $result_total->row();
            $count    =    $row->total;
        }
        return $count;
    }
   function select_listmissionaries($limit, $pgoffset)
   {
           $this->db->limit($limit, $pgoffset);
        $this->db->where('status','1');
        $result_news = $this->db->get('listmissionaries');
          return $result_news->result();
   }


And the view is as follows:

Code:
<table width="593" cellspacing="0" cellpadding="0" style="border: 1px solid rgb(0, 0, 0);">
                      <tbody>
                      <tr>
                        <td width="35" align="center" style="border: 1px solid rgb(0, 0, 0);"><span class="style2">S.No</span></td>
                        <td width="156" align="center" style="border: 1px solid rgb(0, 0, 0);"><span class="style2">Name</span></td>
                        <td width="144" align="center" style="border: 1px solid rgb(0, 0, 0);"><span class="style2">District</span></td>
                        <td width="140" align="center" style="border: 1px solid rgb(0, 0, 0);"><span class="style2">Work Station </span></td>
                      <td width="125" align="center" style="border: 1px solid rgb(0, 0, 0);"><span class="style2">State</span></td>
                      </tr>
                    &lt;?php
                    foreach($listmissionaries as $row)
                    {?&gt;
                      <tr>
                        <td align="center" height="29" style="border: 1px solid rgb(0, 0, 0);">&lt;?php echo $row->id?&gt;</td>
                        <td align="center" style="border: 1px solid rgb(0, 0, 0);">&lt;?php echo $row->name?&gt;</td>
                        <td align="center" style="border: 1px solid rgb(0, 0, 0);">&lt;?php echo $row->district?&gt;</td>
                        <td align="center" style="border: 1px solid rgb(0, 0, 0);">&lt;?php echo $row->workstation?&gt;</td>
                        <td align="center" style="border: 1px solid rgb(0, 0, 0);">&lt;?php echo $row->state?&gt;</td>
                      </tr>
                    &lt;?php }    ?&gt;    
                      </tbody></table>
<div>&lt;?php echo $this->pagination->create_links(); ?&gt;</div>


Messages In This Thread
Group according to a field problem...!!! - by El Forum - 03-03-2011, 11:32 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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