Welcome Guest, Not a member yet? Register   Sign In
display result descending list multiple tables
#1

[eluser]masentinel900[/eluser]
http://i.imgur.com/7buHFuY.jpg
http://pastebin.com/s0zaPF8H


Code:
[Controller]
            function viewContentDropDown(){        
                    $query = $this->content->viewListSector();
                    $data['select'] = $this->input->post('value');
                    $data['query'] = $query->result_array();
                    $this->load->view('ViewProyect', $data);
                    }
    
    
    [Model]
            function viewListSector(){
                    $this -> db -> select('*');
                    $this -> db -> from('sectorProy');
                    $this -> db -> join('itemSecProy','sectorProy.idProy = itemSecProy.idProy', 'left');
                    $this -> db -> join('desItemSector','itemSecProy.idIteSec = desItemSector.idIteSec', 'left');
                    $this -> db -> distinct();
                    $query = $this -> db -> get();
                    return $query;
                    }
    
    [HTML]
    <div id="viewDataSector" >
    <ul id="DropDownList">
    &lt;?php foreach($query as $row):?&gt;
            <li><b>&lt;?php echo $row['nameProy'];?&gt;</b>
            <ul>
                    <li>&lt;?php echo $row['nameIteSec'];?&gt;</li>
            </ul>
        </li>
    &lt;?php endforeach;?&gt;
    </ul>
    </div>
    
    
    [Output]
    
        Alimentos
            Mango
        Industrial
            Maquinaria
        Alimentos
            Arroz
        Alimentos
            Carne
    
    [Target]
    
            Alimentos
                    Mango
                    Arroz
                    Carne
            Industrial
                    Maquinaria



Hello guys!!
This is basically what I have. the [target] tag is what I want to do in my output, I just want to do a descending list but without repeat the records of the first table. This case "Alimentos"
#2

[eluser]rana[/eluser]
as per your requirement, your view code is wrong. See the this code:

Code:
<ul>
                    <li>&lt;?php echo $row['nameIteSec'];?&gt;</li>
            </ul>

This is not going to give you more than one item ever....


To get what you need, first, use order_by method on model as follows:

Code:
$this->db->order_by("","asc")

Then on view, add little check as below:

Code:
&lt;?php foreach($query as $row):?&gt;
            &lt;?php if($row['nameProy'] == $previous){ ?&gt;
                   <li>&lt;?php echo $row['nameIteSec'];?&gt;</li>
             &lt;?php }
             else{
                  if(!empty($previous)){
              ?&gt;
                     </ul>
              &lt;?php
                  }
             ?&gt;
                  <li><b>&lt;?php echo $row['nameProy'];?&gt;</b>
                   <ul>
            &lt;?php }
               $previous = $row['nameProy'] ;
             ?&gt;
        </li>
    &lt;?php endforeach;?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB