This is an old question, but I'm answering now for the benefit of new users.
The short answer is that when you retrieve the results of a database query with result_array, you're getting an array of arrays. Each row is it's own array, and the key for that row is NOT the ID column. It is just a sequential number, starting at zero.
For example, if I have a table like this:
+----+-----------+------------+
| id | username | updated |
+----+-----------+------------+
| 16 | nhageman | 2019-10-29 |
| 20 | hnoland | 2014-02-10 |
| 31 | lpostel | 2020-04-08 |
| 36 | lemmerich | 2016-03-08 |
| 77 | rhegwood | 2017-02-20 |
+----+-----------+------------+
...and run an Active Record query like this:
$results = $this->db
->get('users')
->result_array();
The $results array will look like this:
array (size=10)
0 =>
array (size=3)
'id' => string '16' (length=2)
'username' => string 'nhageman' (length=8)
'updated' => string '2019-10-29' (length=19)
1 =>
array (size=3)
'id' => string '20' (length=2)
'username' => string 'hnoland' (length=7)
'updated' => string '2014-02-10' (length=19)
2 =>
array (size=3)
'id' => string '31' (length=2)
'username' => string 'lpostel' (length=7)
'updated' => string '2020-04-08' (length=19)
3 =>
array (size=3)
'id' => string '36' (length=2)
'username' => string 'lemmerich' (length=9)
'updated' => string '2016-03-08' (length=19)
4 =>
array (size=3)
'id' => string '77' (length=2)
'username' => string 'rhegwood' (length=8)
'updated' => string '2017-02-20' (length=19)
Here's the point:
Notice that the array key for each row is 0 through 4, NOT the row ID.
So you will not get what you expect when you iterate through your array as you did in your question:
// how to do it wrong
foreach ($results as $key => $row) {
echo $key . ':';
echo $row['username'] . '<br>';
}
Wrong results:
0: nhageman
1: hnoland
2: lpostel
3: lemmerich
4: rhegwood
You can see that the $key is just the automatic sequential key assigned to each row. In most cases when dealing with an Active Record result, you can just ignore the key, because the row ID you're looking for is contained in the $row array:
// how to do it right
foreach ($results as $row) {
echo $row['id'] . ':';
echo $row['username'] . '<br>';
}
Correct results:
16: nhageman
20: hnoland
31: lpostel
36: lemmerich
77: rhegwood
Hope this clarifies it for you.
print_r($data['get_all_content'];? And where did you get yourprint_r()?$title = $values['title'];you are getting the title?