Welcome Guest, Not a member yet? Register   Sign In
How can i get ( previous, current and next) data from mysql records?
#3

[eluser]Christophe28[/eluser]
Lucky you! I just programmed something like this! :-)

First you need to know the id of the current file of course.

So to get the info of the current file from (for example) the files table you get:

Code:
$q = "SELECT * FROM files WHERE id = ?";
$current_photo = $this->db->query($q, array(//your_file_id))->row();

To get the next file you write:
Code:
$q = "SELECT * FROM files WHERE id > ? ORDER BY id ASC LIMIT 1";
$next_photo = $this->db->query($q, array(//your_file_id)->row());

To get the previous file you write:
Code:
$q = "SELECT * FROM files WHERE id < ? ORDER BY id DESC LIMIT 1";
$previous_photo = $this->db->query($q, array(//your_file_id)->row());

This is the proper way to do this ;-)

Please let us know if works!

Christophe


Messages In This Thread
How can i get ( previous, current and next) data from mysql records? - by El Forum - 11-04-2010, 01:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB