Ammar Ul Hassan
Ammar Ul Hassan

Reputation: 906

How to get a specific value from a two dimensional arrays

I am creating a module in open cart. In my model i have query which i save it like this.

$zone_id=array();
$zone_id=$this->db->query("SELECT geo_zone_id FROM  `oc_geo_zone` WHERE name= (  SELECT name FROM  `oc_zone`  WHERE zone_id = (  SELECT shipping_zone_id  FROM  `oc_order` WHERE order_id = '".$order_id."' ) ) ");

I can not use print_r() here so i am using log object for debugging. when i write this

$this->log->write($zone_id); 

i get this result.

[num_rows] => 1
[row] => Array
    (
        [geo_zone_id] => 6
    )

[rows] => Array
    (
        [0] => Array
            (
                [geo_zone_id] => 6
            )

    )

How can i fetch the value 6 from this zone_id array i tried this but got nothing.

 $this->log->write($zone_id[0]['geo_zone_id']);

Upvotes: 1

Views: 211

Answers (1)

Nipun Tyagi
Nipun Tyagi

Reputation: 898

Try this one

$result = $zone_id->row['geo_zone_id'];

echo $result;

Opencart query will always returns output in object.

Upvotes: 2

Related Questions