Jump to content

[SOLVED] selected previews record


corillo181

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/78960-solved-selected-previews-record/
Share on other sites

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]

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

}

 

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];
	}
}

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.