Log in

View Full Version : PHP paging



calumogg
08-23-2007, 08:30 PM
Hi all, I have set up a charity website for a person I know (http://www.supportingourtroops.co.uk). It is all working fine, but there is one thing that I cannot work out, PHP paging I have had a look on google and here on the forum but still cant make any sense of it. The backend of the shop stores all the sales records, and the list is growing so I was going to try and add a paging system but cant work out how to do it, here is part of the code that makes the table:


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

<link href="../../res/css/style.css" rel="stylesheet" type="text/css">

<p>Here are the records for the shop:</p>

<form name="form1" method="post" action="">
<table width="80&#37;" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#494949" bgcolor="#EBF7FF" class="text">
<tr>
<td class="text">ID</td>
<td class="text">IP</td>
<td class="text">Name</td>
<td class="text">Email</td>
<td class="text">No. of Bands</td>
<td class="text">Address</td>
<td class="text">Cost</td>
<td class="text">Payment Complete</td>
<td class="text">Order Number</td>
<td class="text">Date</td>
<td class="text">Update</td>
<td class="text">Delete</td>


<?php
while($rows=mysql_fetch_array($result)){
?>
</tr>
<tr>
<td><? echo $rows['id']; ?></td>
<td><? echo $rows['ip']; ?></td>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['email']; ?></td>
<td><? echo $rows['product']; ?></td>
<td><? echo $rows['address']; ?></td>
<td><? echo $rows['cost']; ?></td>
<td><? echo $rows['payment']; ?></td>
<td><? echo $rows['timestamp']; ?></td>
<td><? echo $rows['dateadded']; ?></td>
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">Update</a></td>
<td align="center"><a href="delete.php?id=<? echo $rows['id']; ?>">Delete</a></td>

<?
}
mysql_close();
?>
</tr>
</table>

I would be very greatful if anyone can give me some clues about how to add paging to this. Thanks in advance for any help

james438
08-25-2007, 09:06 AM
Just to give you a cheap answer try looking at the virtual pagination script (http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm). There is some nice code on that page for you to study or just cut and paste.

calumogg
08-25-2007, 08:22 PM
Thanks for the link, but I have finally managed to get a proper PHP one working.