geting variable from url to create a pagination

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maragh876
Forum Newbie
Posts: 1
Joined: Wed Feb 16, 2011 5:28 pm

geting variable from url to create a pagination

Post by maragh876 »

am creating a gallery to display 1 image at a time, with link to the next image, now the problem is that i get 2 variable from a url which i used the $_request[] function to get them, the first select statment work, wen u navigate to the page, but wen u click the next link its not reading the $request function, everything just go dead.... any help any one

Code: Select all

<?php include('include/header.php');?>
<?php   $gallery_id = $_GET['gallery_view']; 
 $album = $_GET['album'];?>
<span><a href="default.php"><img src="img/logo.png" /></a></span>
</div>
<ul>
<li ><a href="default.php">home</a></li>
<li><a href="career.php">career</a></li>
<li><a href="realestate.php">realestate</a></li>
<li><a href="shopping.php">shopping</a></li>
<li><a href="image.php">image</a></li>
<li><a href="about.php">about us</a></li>
<li><a href="contact.php">contact us</a></li>
</ul>
<div id="login">
<?php
if (isset($_SESSION['user'])){
	echo "Welcome " . $_SESSION['user'] . " | <a href=\"logout.php\">logout </a>"; 
	}else{
		echo"
 <a href=\"register.php\">register</a>
 | <a href=\"login.php\">login </a>
 ";
		}

 ?>
</div>
</div>
</div>
<hr class="hide" />
<div id="main-outer-wrap">
<div  id="main-wrap">

 <div id="content">
   <?php
   
   
   /// max per page

$per_page = 1;

// start varable

$start = $_GET['start'];


///record count

  $record_count = mysql_num_rows(mysql_query("SELECT * FROM  gallery WHERE album_id = '$album'"));
      

//max page

$max_page = $record_count/$per_page; /// this may contain decimal place

if(!$start)
	$start = 0;
/////////////////////////////////////////////////////////



   ////////////////////////////////////////////////
   $gallery = mysql_query("SELECT * FROM gallery WHERE  album_id = '$album' AND id = '$gallery_id' LIMIT $start , $per_page");
    
      while( $gallery_row = mysql_fetch_assoc($gallery))
	  {
		  echo "<h1 class='address'>" .$gallery_row['description']."</h1>";
		  echo "</p>";
		  echo"<p class='pagination'>"; 
		  echo "<img src='gallery/$album/".$gallery_row['img']."' width='500px' height='350px'/><br/>";
		  echo "</p>";
		   echo"<p class='next_prev'>"; 
		  // setup next and prev page	
	
	$perv = $start - $per_page;
	$next = $start + $per_page;
	
	/// show prev button
	if(!($start<=0)){
	echo " <a href='gallery_view.php?album=$album&gallery_view=$gallery_id&start=$perv'>prev</a> ";
	}
	
	
	// show next button
	if(!($start >= $record_count - $per_page)){
	echo " <a href='gallery_view.php?album=$album&gallery_view=$gallery_id&start=$next'>next</a> ";
	}	
		  echo "</p>";
		
		  }
	 
?>
 </div>
 <hr class="hide" />
 <div id="sidebar">
  <p>&nbsp;</p>
 </div>
 <p>&nbsp;</p>
</div>

</div>
<?php include('include/footer.php');?>
jankidudel
Forum Commoner
Posts: 91
Joined: Sat Oct 16, 2010 4:30 pm
Location: Lithuania, Vilnius

Re: geting variable from url to create a pagination

Post by jankidudel »

The easiest way I think is just to look on your $next value from the url and then check your table if you have this much rows.
Post Reply