title: How to group the data under same heading through looping
body: <p>I am trying to get data from two joined tables,From one table I am collecting list heading and from second joined table i am collecting list data.</p>
  
  <p>Code for Model:</p>
  
  <pre><code>function view_searching_type_items()
  {
    $this-&gt;db-&gt;select("searching_type.searchtype_name, search_type_item.st_item_id_pk, search_type_item.searchtype_itemname");
    $this-&gt;db-&gt;from('searching_type');
    $this-&gt;db-&gt;join('search_type_item', 'search_type_item.st_id_fk = searching_type.st_id_pk');
    $query = $this-&gt;db-&gt;get();
    return $query-&gt;result_array(); 
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>$url1 = 'http://localhost/pakistanmenu/index.php/Restaurant/ViewSearchingTypeItems';
      $curl_hand = curl_init($url1);
      curl_setopt($curl_hand, CURLOPT_TIMEOUT, 5);
      curl_setopt($curl_hand, CURLOPT_CONNECTTIMEOUT, 5);
      curl_setopt($curl_hand, CURLOPT_RETURNTRANSFER, true);
      $data1 = curl_exec($curl_hand);// json_decode($data)
      curl_close($curl_hand);
      $result['searchingtype'] = (array) json_decode($data1,true);
  
      $this-&gt;load-&gt;view('header');
      $this-&gt;load-&gt;view('index',$result);
      $this-&gt;load-&gt;view('footer');
  </code></pre>
  
  <p>View Code:</p>
  
  <pre><code>&lt;?php foreach ($searchingtype as $searchingtyp):?&gt;
  
   &lt;ul class="list-group checked-list-box"&gt;
      &lt;h1 class="page-header leftsidebar-heading"&gt;&lt;?php echo $searchingtyp['searchtype_name'];?&gt;&lt;/h1&gt;
  
       &lt;li class="list-group-item" data-style="button" style="cursor: pointer;"&gt;
           &lt;span class="state-icon glyphicon glyphicon-unchecked"&gt;
  
           &lt;/span&gt;
  
           &lt;?php echo $searchingtyp['searchtype_itemname'];?&gt;
  
           &lt;input type="checkbox" class="hidden"&gt;
  
       &lt;/li&gt;
  </code></pre>
  
  <p></p>
  
  
  
  <p>Kindly check the below image i have shown the output of this code, and also i have draw what output i need thanks, Kindly help me. thanks </p>
  
  <p><a href="https://i.stack.imgur.com/QOVmU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QOVmU.png" alt="enter image description here"></a></p>