corillo181 Posted November 26, 2007 Share Posted November 26, 2007 hi, i have a data base which has 20 records.. if the person is in record 15 i want the to see [13][14]15[16][17] this is easy to, but if you use selecte record - 2 and you delete number 14 the record will look [13]15[16][17] but i want [12][13]15[16][17] if record 14 is deleted this is the code that i have right now <?php public function nextPhoto(){ $query= "SELECT * FROM tra_gallery_photo WHERE album_id='{$this->album_id}' AND photo_id >{$this->photo_id} LIMIT 2"; $result= $this->db->query($query); $num = $this->db->num_rows($result); if($num>0){ while($array =$this->db->fetch_array($result)){ echo '<a href="displayimage.php?album='.$array['album_id'].'&ptd='.$array['photo_id'].'"><img width="100" src="image/'.basename($array['thumb_path']).'" alt="'.basename($array['thumb_path']).'" /></a>'; } } } public function prePhoto(){ $query= "SELECT * FROM tra_gallery_photo WHERE album_id='{$this->album_id}' AND photo_id <{$this->photo_id} LIMIT 2 "; $result= $this->db->query($query); $num = $this->db->num_rows($result); if($num>0){ while($array =$this->db->fetch_array($result)){ echo '<a href="displayimage.php?album='.$array['album_id'].'&ptd='.$array['photo_id'].'"><img width="100" src="image/'.basename($array['thumb_path']).'" alt="'.basename($array['thumb_path']).'" /></a>'; } } } ?> by the way this code comes from a long class there is no problem with the class i just want to know how to do this. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 26, 2007 Share Posted November 26, 2007 pagination is what u are going for I think Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 26, 2007 Author Share Posted November 26, 2007 but with pictures. and photothat can be deleted. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 26, 2007 Author Share Posted November 26, 2007 no clue cool dude/? Quote Link to comment Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 Look at my post HERE Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 26, 2007 Author Share Posted November 26, 2007 the link is no good. Quote Link to comment Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 try it again. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 26, 2007 Author Share Posted November 26, 2007 that is not my question... i know to to loop my problem is in the MYSQL i need to get the last 2 records before the current one. "SELECT id FROM table WHERE id<$current_id LIMIT 2" ^^^^^^^^^^^^^^^^^^^^ this solves the problem but it shows me the first 2 records 1 and 2 since they are less than the current id. and if i put ORDER BY id DESC it shows the record backwards [id18][id17]id19[id20][id21] Quote Link to comment Share on other sites More sharing options...
xyn Posted November 26, 2007 Share Posted November 26, 2007 LIMIT 2,2 Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Author Share Posted November 27, 2007 XYN ARE YOU SURE YOU UNDERSTAND MY QUESTION? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Author Share Posted November 27, 2007 i try using array and doing a backward count down but they add tot he array in a descing order also.. i try putting the images like this $p[2] = 'url'; $p[1] = 'url'; but when i do a var dump the outcome is array(2){ [2]=>url, [1]=>url } not the expected array(2){ [1]=>url, [2]=>url } Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Author Share Posted November 27, 2007 this is what i ended up doing just in case somoene comes with a faster better solution. i order the record in descing form added them to a array and then count the array backwards this gave me the desire result public function prePhoto(){ $preArray = array(); $query= "SELECT * FROM tra_gallery_photo WHERE album_id='{$this->album_id}' AND photo_id <{$this->photo_id} ORDER BY photo_id DESC LIMIT 2 "; $result= $this->db->query($query); $num = $this->db->num_rows($result); $count = 0; if($num>0){ while($array =$this->db->fetch_array($result)){ $preArray[$count] = '<a href="displayimage.php?album='.$array['album_id'].'&ptd='.$array['photo_id'].'"><img width="100" src="image/'.basename($array['thumb_path']).'" alt="'.basename($array['thumb_path']).'" /></a>'; $count++; } } for($i=1;$i>=0;$i--){ echo $preArray[$i]; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.