• No categories
Jun
1
2011

Next Previous Buttons for MySql in PHP

Hello, today i am writing simple code how to iterate between lists of records in table. First of all php logic to maintain starting id of list and then a select query and after that adding buttons. The wrapper table will contain the records fetched from query results.

include("connection.php");
if(isset($_POST['startid']) && isset($_POST['nextbtn']))
{
$startid=$_POST['startid']+30;
}
else if(isset($_POST['startid']) && isset($_POST['prevbtn']))
{
if($_POST['startid']>=30)
{
$startid=$_POST['startid']-30;
}
else
{
$startid=0;
}
}
else
{
$startid=0;
}
$results=mysql_query("select * from customer_details order by id asc limit ".$startid.", 30 ");
if(mysql_num_rows($results)>0)
{
?>
<table id="customerslist" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
<tr><td colspan="12" align="center">
<form name="nextprev" id="nextprev" method="post" action="customerslist.php">
<table><tr>
<td style="border:none"><input type="submit" name="prevbtn" id="prevbtn" value="<< Previous List" /></td>
<td style="border:none"><input type="text" name="startid" id="startid" size="10" value="<?php echo $startid; ?>" style="display:none" /> </td>
<td style="border:none"><input type="submit" name="nextbtn" id="nextbtn" value="Next List >>" /></td></tr></table>
</form>
</td>

after the last td, all rows will contain fetched data and include 12 columns from customer_details table.

About the Author:

Comments are closed.