title: how can i store values in array using foreach loop...?
body: <p>I am working under Opencart. My big problem is should store values in array for displaying result. And my question is >> I want to fetch product in Db which under the particular location. for example if the location Bangalore, Bangalore products come alone. </p>
  
  <p>query Shown below: </p>
  
  <pre><code>public function getvendorsbycity($city,$products)
  
  {
      $selected_vendor = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "vendors where city='".$city."'");
  
      if(isset($selected_vendor-&gt;rows) &amp;&amp; !empty($selected_vendor-&gt;rows))
      {
          $i=0;
          foreach($selected_vendor-&gt;rows as $val)
          {
  
              $selected_array=array();
              if(isset($products) &amp;&amp; !empty($products))
              {
  
                  foreach($products as $p_val)
                  {
  
  
                      $selected_products = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "vendor v LEFT JOIN " . DB_PREFIX . "product_description pd ON v.vproduct_id=pd.product_id WHERE vendor='".$val['vendor_id']."' AND pd.name LIKE '%".$p_val['name']."%'");
  
                      if(isset($selected_products-&gt;rows) &amp;&amp; !empty($selected_products-&gt;rows))
                      {
                          $selected_array[]=$selected_products-&gt;rows;
                      //I am getting result here..!
  
                      }
                  }
              }
  
              $i++;
          }
      }
  
      //I could't get result here.! I should return the array here.
      return $selected_array;
  }
  </code></pre>
  
  <p>Can any one help me..! Thanks in advance .</p>