Pagination within a html table is not working
Posted: Wed Nov 18, 2009 5:45 am
hi, the code is responding fine when its outside the html table but within the table the Prev 1 2 3 4 next is not showing. any ideas??
<table width="487" height="672" border="1" align="left" cellpadding="3" cellspacing="3" background="/bgtr.gif">
<tr align="center" valign="middle">
<td width="23%" height="28" bgcolor="#FFFFFF"> <h3 align="center">Available
</h3></td>
</tr>
<tr align="center" valign="middle">
<td height="626" align="left" valign="top" bgcolor="#FFFFFF">
<?php
include ("connect.php");
// max display per page
$per_page = 50;
// get start variable
$start = $_GET ['start'];
// count record
$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats"));
//count max pages
$max_pages = $record_count / $per_page; // may come out as a decimal
if (!$start)
$start = 0;
// display data
$get = mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$select= $row['type'];
$title= $row['title'];
$location= $row['location'];
echo "<div><b>$title</b></div>";
echo "<br>";
echo "$select";
echo "<br>";
echo "$rent";
echo "<br>";
echo "$location";
}
// setup the prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo " <a href='londonfc_flats.php?start=$prev'><b> «« Prev </b></a> ";
//show page numbers
// set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo " <a href='londonfc_flats.php?start=$x'>$i |</a> ";
else
echo " <a href='londonfc_flats.php?start=$x'><b> $i|</b></a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='londonfc_flats.php?start=$next'><b> Next »»</b></a> ";
?>
</td>
</tr>
</table>
<table width="487" height="672" border="1" align="left" cellpadding="3" cellspacing="3" background="/bgtr.gif">
<tr align="center" valign="middle">
<td width="23%" height="28" bgcolor="#FFFFFF"> <h3 align="center">Available
</h3></td>
</tr>
<tr align="center" valign="middle">
<td height="626" align="left" valign="top" bgcolor="#FFFFFF">
<?php
include ("connect.php");
// max display per page
$per_page = 50;
// get start variable
$start = $_GET ['start'];
// count record
$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats"));
//count max pages
$max_pages = $record_count / $per_page; // may come out as a decimal
if (!$start)
$start = 0;
// display data
$get = mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$select= $row['type'];
$title= $row['title'];
$location= $row['location'];
echo "<div><b>$title</b></div>";
echo "<br>";
echo "$select";
echo "<br>";
echo "$rent";
echo "<br>";
echo "$location";
}
// setup the prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo " <a href='londonfc_flats.php?start=$prev'><b> «« Prev </b></a> ";
//show page numbers
// set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo " <a href='londonfc_flats.php?start=$x'>$i |</a> ";
else
echo " <a href='londonfc_flats.php?start=$x'><b> $i|</b></a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='londonfc_flats.php?start=$next'><b> Next »»</b></a> ";
?>
</td>
</tr>
</table>