how can i store values in array using foreach loop...?
05:07 02 Apr 2015

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.

query Shown below:

public function getvendorsbycity($city,$products)

{
    $selected_vendor = $this->db->query("SELECT * FROM " . DB_PREFIX . "vendors where city='".$city."'");

    if(isset($selected_vendor->rows) && !empty($selected_vendor->rows))
    {
        $i=0;
        foreach($selected_vendor->rows as $val)
        {

            $selected_array=array();
            if(isset($products) && !empty($products))
            {

                foreach($products as $p_val)
                {


                    $selected_products = $this->db->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->rows) && !empty($selected_products->rows))
                    {
                        $selected_array[]=$selected_products->rows;
                    //I am getting result here..!

                    }
                }
            }

            $i++;
        }
    }

    //I could't get result here.! I should return the array here.
    return $selected_array;
}

Can any one help me..! Thanks in advance .

php arrays opencart resultset