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

Link to comment
Share on other sites

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

}

 

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.