[solved] help with syntax for result set - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [solved] help with syntax for result set (/showthread.php?tid=13526) |
[solved] help with syntax for result set - El Forum - 11-25-2008 [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 [solved] help with syntax for result set - El Forum - 11-25-2008 [eluser]iainco[/eluser] Model: Code: function get_nextprev($album, $id) { View: Code: foreach($nextprev as $item): [solved] help with syntax for result set - El Forum - 11-26-2008 [eluser]Dave Rau[/eluser] I ended up with this: controller: Code: $data['nextprev'] = $this->simple_gallery->get_nextprev($this->uri->segment(3), $this->uri->segment(4)); view: Code: $next_id = $nextprev->row('next_id'); If someone is making a photo gallery here's a GREAT query for next/previous links in an specific order. I have albums and I'm sorting by ID, so the newest images are first in the list and you go backwards in time to see other images in the album. Here's the query: Code: SELECT id, title, @a := id, ( SELECT id FROM gallery WHERE album = '$album' AND id < @a ORDER BY id DESC LIMIT 1 ) AS prev_id, ( SELECT id FROM gallery WHERE album = '$album' AND id > @a ORDER BY id ASC LIMIT 1 ) AS next_id FROM gallery WHERE album = '$album' and id = '$id' order by id |