Welcome Guest, Not a member yet? Register   Sign In
Am I using previous_row() next_row() correctly here?
#1

[eluser]Unknown[/eluser]
Hello I am creating a picture gallery and am using the database functions next_row() and previous_row() in order to find id values for my "next picture" and "previous picture" buttons.

I just wanted to know if I am using next_row() and previous_row() as they were intended, as there is very little documentation on their use, and no examples of their use.

Code:
// Get all id's for pictures
$this->db->select('id');
$query = $this->db->get('pictures');

// Search for currently displayed picture
foreach ($query->result() as $key => $row)
{
    // Currently displayed picture found
    if($row->id == $id)
    {
        // Find next rows id, assign to $data['picture_next']
        $query->current_row = $key;
        $row_next = $query->next_row();
        $data['picture_next'] = $row_next->id;

        // Find previous rows id, assign to $data['picture_previous']
        $query->current_row = $key;
        $row_prev = $query->previous_row();
        $data['picture_previous'] = $prev_prev->id;
    
        break; // Data found, stop.
    }
}

// ... pass $data array to view etc
Notice how I am writing to the $query object's member variable "current_row" directly. Is this right? I can't see any other way to do this in DB_result.php (unless I am missing something, please tell me).

If I am doing this correctly, PLEASE put an example in the official documentation as it took me hours to figure out how to use next_row() and previous_row()




Theme © iAndrew 2016 - Forum software by © MyBB