display fix set of data in table....

Reply

Join Date: Dec 2007
Posts: 6
Reputation: manish_gajjar is an unknown quantity at this point 
Solved Threads: 0
manish_gajjar manish_gajjar is offline Offline
Newbie Poster

display fix set of data in table....

 
0
  #1
Jan 3rd, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: display fix set of data in table....

 
0
  #2
Jan 3rd, 2008
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: display fix set of data in table....

 
0
  #3
Jan 3rd, 2008
Simplest 'next-forward' script, just to get the idea on how it works. You will find much more efficient code on the net.
  1. <?php
  2. $offset=isset($_REQUEST['offset'])?$_REQUEST['offset']:0;
  3. $conn=mysql_connect("localhost","root");
  4. mysql_select_db("test");
  5. $total=mysql_num_rows(mysql_query("select * from test"));
  6. $query="select * from test limit $offset,5";
  7. $result=mysql_query($query);
  8. while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
  9. print_r($row);
  10. }
  11. if($offset==0){
  12. $next_offset=$offset+1;
  13. $prev_offset=0;
  14. } elseif($offset == $total) {
  15. $next_offset=$total;
  16. $prev_offset=$offset-1;
  17. } else {
  18. $next_offset=$offset+1;
  19. if($next_offset==$total){
  20. $next_offset=$total;
  21. }
  22. $prev_offset=$offset-1;
  23. }
  24. echo "<a href=test.php?offset=$prev_offset>Prev</a>";
  25. echo "<a href=test.php?offset=$next_offset>Next</a>";
  26. ?>

Cheers,
Nav
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC