Pagination

Posted on 16th Feb 2014 by admin

Hi All,

I think I'm finally getting somewhere with pagination!

I can now submit a query and get the correct number of records back with the correct number of pages.

My only problem is, when I press the page numbers or the next button the records disappear.

If anyone gets time, could you take a look at my code and tell me where I’m going wrong please?

Jamie

Code: [Select]<?php

require("conf.php");


//max displayed per page
$per_page = 2;

//get start variable
$start = $_GET['start'];

$udfin = $_POST['udf'];

//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM cy_equ WHERE udf = $udfin"));

//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal

if (!$start)
$start = 0;

//display data
$get = mysql_query("SELECT * FROM cy_equ WHERE udf = $udfin LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$id = $row['id'];
$ext = $row['ext'];
$equ = $row['equ'];

echo $id." (".$ext.") (".$equ.")<br />";

}

//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<=0))
echo "<a href='qqq.php?start=$prev'>Prev</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='qqq.php?start=$x'>$i</a> ";
else
echo " <a href='qqq.php?start=$x'><b>$i</b></a> ";
$i++;
}

//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='qqq.php?start=$next'>Next</a>";

?>
<h3> UDF Query </h3>
<form name="form1" method="post" action="http://localhost/qqq.php">
<p> Input UDF: <input type="number" name="udf" value= "<?php echo $udfin; ?>" size="1" maxlength="4"/></p>



<p><input type="submit" name="submit" value="GET DATA"/></p>


</form>

Other php-forum