[eluser]Dave Rau[/eluser]
I don't know how to properly reference the next_id and prev_id rows that mysql is returning. Check the view code below; that's where my syntax is busted
If my result is contained inside $data['nextprev'], how do I reference the first (and only) result set for prev_id and next_id fields in my database?
Code:
// view
// this isn't right, but it's close I hope!
echo $nextprev->result([0])['prev_id'];
// model
// this works and returns the correct result
function get_nextprev($album, $id) {
$album_t = $this->app->config->item('gallery_table','simple_gallery');
$query = "SELECT id, title, @a := id, ( SELECT id FROM {$this->app->config->item('gallery_table','simple_gallery')} WHERE album = '$album' having id < @a ORDER BY title DESC LIMIT 1 ) AS prev_id, ( SELECT id FROM gallery WHERE album = '$album' having id > @a ORDER BY title ASC LIMIT 1 ) AS next_id from {$this->app->config->item('gallery_table','simple_gallery')} where album = '$album' and id = '$id'";
$results = $this->db->query($query);
return $results;
}
// controller
function image() {
$this->db->where('id', $this->uri->segment(4));
$data['query'] = $this->db->get('gallery');
$data['nextprev'] = $this->simple_gallery->get_nextprev($this->uri->segment(3), $this->uri->segment(4));
$this->load->view('view_photos/image', $data);
}