Jump to content

[SOLVED] Anyone familiar with pagination? - simple table


DamienRoche

Recommended Posts

I am seriously confused here. I have tried to adapt two scripts I found on the net but haven't been able to make any ground.

 

I have 4 rows with 2 fields. All I want to do is to display them 2/page

 

Is there a simple way to do this? Any pointers or references or code you use would be great.

 

Here is my current code:

 

<?php

$table = "pending";

$dbh = mysql_connect($hst99, $user99, $pass99);
mysql_select_db("database", $dbh);
$data=mysql_query("SELECT * from $table ORDER BY tstamp");
  
$num = mysql_num_rows($data);
echo "<br>num rows: $num<br><br>";

$max = 2; //amount of articles per page. change to what to want

$p = $_GET['p'];

if(empty($p))

{$p = 1;}

$limits = ($p - 1) * $max; 

$sql = mysql_query("SELECT * FROM $table LIMIT ".$limits.",$max") or die(mysql_error());

//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT(*) AS tot FROM $table"),0);	
$totalres = $num;
//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max); 


### WHILE

while($fetch=mysql_fetch_array($data)){

$id = mysql_real_escape_string($fetch['id']);
$tstamp = mysql_real_escape_string($fetch['tstamp']);	
$name = mysql_real_escape_string($fetch['phot']);	
$email = mysql_real_escape_string($fetch['email']);	
$website = mysql_real_escape_string($fetch['website']);	
$durl = mysql_real_escape_string($fetch['durl']);	
$expl = mysql_real_escape_string($fetch['expl']);	
$img_url = mysql_real_escape_string($fetch['img_url']);
$img_nm = mysql_real_escape_string($fetch['img_nm']);
$width = mysql_real_escape_string($fetch['width']);
$height = mysql_real_escape_string($fetch['height']);

###





?>
<div class='img' style='width:<? echo $width ?>px;height:<? echo $height ?>px;background:url(<?php echo "uploads/$id/$img_nm"; ?>);'></div>
<?php echo "$tstamp, $name, $email"; ?><br />
<?php echo "$website,$durl"; ?><br>
<?php echo $expl ?><br>
<?php echo $img_url ?><br>
<?php echo $img_nm ?><br>
<?php echo "$width X $height"; ?><br><br>
<?php } 


for($i = 1; $i <= $totalpages; $i++){ 

//this is the pagination link

echo "<a href='main99.php?p=$i'>$i</a>|";

}
?>

Link to comment
Share on other sites

Sorry, next time I'll be more specific. It was just showing all of the records and the pagination links....it was a mess. Any way, I didn't know phpfreaks had a tut on it, so thank you for the link coz I just used that code and had it working within 5 minutes.

 

Thanks!

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.