lucky
lucky

Reputation: 21

CodeIgniter need to get one row?

My query is

    $query = $this->db->get('users');
    foreach ($query->result() as $row) {

        $mobile=$row->mobileNo;

I need particular row1 mobileno, but it getting all mobile numbers from db .....

Upvotes: 0

Views: 200

Answers (3)

reignsly
reignsly

Reputation: 502

$query = $this->db->get('users')->row();
$mobile = $query->mobileNo;

Upvotes: 0

Liberto
Liberto

Reputation: 41

Probably you need to use more specific queries using limit 1, order by, where. Also you can use "each" instead of foreach in this code.

Upvotes: 0

Zeeshan
Zeeshan

Reputation: 801

You need to execute this query to get first row from your table

$this->db->select('mobileNo');
$this->db->limit(1);
$result = $this->db->get('users')->result();

// This will return you single record
print_r($result);

Upvotes: 1

Related Questions