I am using php version 4.3.3.
The below was my pagination code.
My problem is that when i run this code in my computer, i wall fail becouse of the hyperlink of the pagination not function when i click it. But when i run in other people computer, It was no problem at all. I wonder to know what happen to my coding . Is it different version of php also reflect the output?
<?
//required file for database connection
require("config.php");
$query = "SELECT ID,Name FROM listofitem ";
$result = mysql_query($query);
$page_name="list.php";
$num_record = mysql_num_rows($result);
$display =5;
$XX = 'Sorry, no results were found!';
// If there are no records then startrow
// is 0
if (empty($startrow)) {
$startrow=0;
}
$query2 = "SELECT ID,Name FROM listofitem LIMIT $startrow, $display";
$result2 = mysql_query($query2);
echo "<table border='1'align=center>
<th bgcolor='#CCCFFF' align=left><font face='arial,verdana,helvetica' size='2'><br>Name</font></th>
$counter = 0;
while(list($ID,$Name) = mysql_fetch_array($result2)) {
if ($counter == 3) {
$counter = 0;
}
echo"<td><font face='arial,verdana,helvetica' size='2'><a href='InformationPage.php?id={$ID}'>{$Name}</a></font></td>";
echo"</tr>";
$counter = $counter + 1;
}
// End loop
// Calculate the previous results, only
// print 'Previous' if startrow is not equa
// l to zero
if ($startrow != 0) {
$prevrow = $startrow - $display;
echo"<a href='$page_name?startrow=$prevrow'>prev</a> ";
}
// Calculate the total number of pages
$pages = intval($num_record / $display);
if ($num_record % $display) {
$pages++;
}
// Print the next pages, first check if
// there are more pages then 1
if ($pages > 1) {
for ($i=1; $i <= $pages; $i++) { // Begin loop
$nextrow = $display * ($i - 1);
echo"<a href='$page_name?startrow=$nextrow'>[$i]</a> ";
}
}
//End loop
// Check if we are at the last page, if
// so, dont print 'Next'
if (!(($startrow / $display) == $pages) && $pages != 1) {
// not the last page so print 'Next'
$nextrow = $startrow + $display;
echo"<a href='$page_name?startrow=$nextrow'>next</a>";
}
// If there are no results at all
if ($num_record < 1) {
echo"<table border=0 width=795><tr><td>$XX</td></tr></table>";
echo"</table>";
echo"<br><br><br><a href='index.php? '>[back]</a>";
}
?>