I’ve created a site for users to upload their images. However, I would like to create a next image button (or previous image button). The problem is, how can I get the “next” and “previous” id’s?
The SQL structure looks like this,
CREATE TABLE IF NOT EXISTS `images` (
`id` int(9) NOT NULL AUTO_INCREMENT,
`user_id` int(9) NOT NULL,
`url` varchar(450) NOT NULL,
`upload_time` int(9) NOT NULL,
`upload_ip` varchar(250) NOT NULL,
`warnings` int(9) NOT NULL,
`deleted` int(9) NOT NULL,
PRIMARY KEY (`id`)
)
As you see, I cannot just add a “+1” because other users may get the next id etc. Is there any good easy solution for this? Maybe an example?
I’m using codeigniter, and this is how I pull out data and views a single image
PHP
// Get current image by id
function get_single_image($user_id, $image_id)
{
$this->db->where('id', $image_id);
$this->db->where('user_id', $user_id);
$this->db->where('deleted', '0');
$query = $this->db->get('images');
if($query->num_rows() > 0)
{
$query = $query->result_array();
return $query[0];
}
return false;
}
Decided to Google CodeIgniter myself for curiosity – so here’s my comment dressed up in syntax 🙂
Select the next image
Select the previous image