0

this is my module

function order_alert($email){

        $this->db->select("tbl_customer_registration.cus_mobile");
        $this->db->from('tbl_customer_registration');
        $this->db->where('tbl_customer_registration.cus_email', $email);
        $query = $this->db->get();
        echo '<pre>';
        print_r($query->result()) ;

}

It return the following result for the above code

Array
(
    [0] => stdClass Object
        (
            [cus_mobile] => 0716352642
        )

)

In the contoller I use foreach

foreach($result as $row) :
echo $row['cus_mobile'];

to get [cus_mobile] out of the above array but it gives me all [cus_mobile] rows in the tbl_customer_registration.

How do I get the only [cus_mobile] => 0716352642 out of it.

0

3 Answers 3

1
$row->cus_mobile

since you have an array of objects.. not really sure if i got your question

(UPDATED) Try this..

foreach($query->result() as $row) {
   echo $row->cus_mobile;
}
Sign up to request clarification or add additional context in comments.

Comments

0

If I got well your question, what your doing is retrieving data as array of objects and trying to access its data as pure array. To do so as you mean you might retrieve data result as an array there is method called result_array() you might use it instead $query->result().

echo '<pre>';
print_r($query->result_array()) ;

foreach($result as $key => $row) :
echo $row['cus_mobile'];

Comments

0
    function order_alert($email){

    $this->db->select("tbl_customer_registration.cus_mobile");
    $this->db->from('tbl_customer_registration');
    $this->db->where('tbl_customer_registration.cus_email', $email);
    $query = $this->db->get();
   if($query->num_rows()==1)
    $result_row = $query->row();
    return $result_row;
    else 
    return false;

}

    foreach($result_row as $row) {
    echo $row->cus_mobile;
    }

This will work for if result has one row... now to need to handle the case for greater than one row.Thanks

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.