DamienRoche Posted December 15, 2008 Share Posted December 15, 2008 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>|"; } ?> Quote Link to comment Share on other sites More sharing options...
B34ST Posted December 15, 2008 Share Posted December 15, 2008 If you show us some code im sure someone on here will be able to help you fix your problem. Otherwise take a look at the Pagination Tutorial on here. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 15, 2008 Share Posted December 15, 2008 so what is it doing or not doing? Quote Link to comment Share on other sites More sharing options...
DamienRoche Posted December 15, 2008 Author Share Posted December 15, 2008 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! 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.