Hi guys...Good morning...I have following code.

<?php
$pid=$_GET['pid'];
$conn=mysql_connect('localhost','root','') or die("Cannot connect to server");
mysql_select_db('developer',$conn) or die("Cannot connect to database");
$sql="select cnode,item,pnode from listviews where cnode='$pid'";
$res=mysql_query($sql) or die("Cannot execute query");      
while($ar=mysql_fetch_array($res))
{   
    $itm=$ar[1];
    $pid=$ar[0];
}
$sql="select cnode,item,pnode from listviews where pnode='$pid'";
$res=mysql_query($sql) or die("Cannot execute query");      
echo "<table border='1'>";
if($pid==0)
    echo "<th colspan=2>Parent Items</th>";
else
    echo "<th colspan=2>$itm</th>";
while($ar=mysql_fetch_array($res))
{   
    echo "<tr><td>$ar[0]</td><td>$ar[1]</td>";
}
echo "</table>";
?>

Now i want to display only five rows per page...and using next button i want to see next five records...How it is possible to display it using PHP...This page is called by ajax script...Please show me the way...Thank you...

Simplest 'next-forward' script, just to get the idea on how it works. You will find much more efficient code on the net.

<?php
$offset=isset($_REQUEST['offset'])?$_REQUEST['offset']:0;
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
$total=mysql_num_rows(mysql_query("select * from test"));
$query="select * from test limit $offset,5";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
	print_r($row);
}	
if($offset==0){
	$next_offset=$offset+1;
	$prev_offset=0;
} elseif($offset == $total) {
	$next_offset=$total;
	$prev_offset=$offset-1;
} else {
	$next_offset=$offset+1;
	if($next_offset==$total){
		$next_offset=$total;
	}
	$prev_offset=$offset-1;
}
echo "<a href=test.php?offset=$prev_offset>Prev</a>";
echo "<a href=test.php?offset=$next_offset>Next</a>";
?>

Cheers,
Nav

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.