1

i am using

$sql= "select *  from tablename where id=1";
$query= $this->db->query($sql);
$row = $query->result_array();

in model of codeigniter.My table consists of a field name 'ID'.how to retrive ID from $row.

$id = $row['ID'];

which shows

<p>Message:  Undefined index: DOCUMENT_ID</p>

how to solve this

1
  • Your question is wrong. The message refers to the index 'DOCUMENT_ID' but you are trying to access 'ID' so this cannot be the message from the above code. You have figured it out below - the $row array is multidimensional as it could have many rows within it Commented Jan 23, 2015 at 16:47

4 Answers 4

1

I got the answer $Id = $row[0]['ID'];

Sign up to request clarification or add additional context in comments.

Comments

0

I hope this might help you

$sql= "select *  from tablename where id=1";
$query= $this->db->query($sql);
foreach($query->result() as $values){
echo $values->id;

}

Comments

0

If the id is a unique key in your database, as it seems, you should do this:

$sql= "select *  from tablename where id=1";
$row = $this->db->query($sql)->row();

It fetches the first row of the result. As id is unique, you only want to fetch one row too.

To get id, simply do:

$id = $row['ID'];

Just an optimized way as compared to the solution you have found.

Comments

0

If you get the row as

$row = $this->db->query($sql)->row();
$id = $row->id;

you get the first row as an object and should access it as $row->id. You can also use

$row = $this->db->query($sql)->row_array();
$id = $row['id'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.