Welcome Guest, Not a member yet? Register   Sign In
array index problem
#1

[eluser]satterle[/eluser]
This is driving me crazy. I keep getting a message: "undefined index: on_id". I have no idea what's causing the problem. Any help greatly appreciated.
Code:
function _get_last_sibling($o_id, $on_pid)
    {
    $this->db->select('on_id');
    $this->db->where('o_id', $o_id);
    $this->db->where('on_pid', $on_pid);
    $query = $this->db->get('outline_notes');
    $row = $query->last_row('array');

    print 'on_id : '.$row['on_id'];  // print to verify, which it does

    $on_id = $row['on_id'];
    ...
#2

[eluser]Henry Weismann[/eluser]
Wow that is wierd! Try commenting out:
$on_id = $row['on_id'];

Do you still get the error.

Try
$this->db->select('on_id as test');
Then
$on_id = $row['test'];
print 'on_id : '.$on_id; // print to verify
#3

[eluser]JoostV[/eluser]
Sounds like your query is not returning results. Check with
Code:
echo 'numrows = ' . $query->num_rows();

To prevent errors from popping up, check if any rows were returned before processing.
Code:
// Query database for last sibling
$this->db->select('on_id');
$this->db->where('o_id', $o_id);
$this->db->where('on_pid', $on_pid);
$query = $this->db->get('outline_notes');

if ($query->num_rows() > 0) {
    $row = $query->last_row('array');
    $on_id = $row['on_id'];
    // Some more processing...
}
else {
    // No results were returned
    // Send a message to the user or do something else to handle error more gracefully
    echo 'Could not retrieve any records';
}

Also, if you wish to retrieve just one record, you might want to try adjust your SQL so that you can limit the result using $this->db->limit(1) for a more efficient query.
#4

[eluser]d_anank[/eluser]
check this:
Code:
$this->db->select('on_id');
$this->db->from('table_name'); //--> you should using this function to select the table from
$this->db->where('o_id', $o_id);
$this->db->where('on_pid', $on_pid);
$query = $this->db->get('outline_notes');
$row = $query->last_row('array');




Theme © iAndrew 2016 - Forum software by © MyBB