IT Community - Software Programming, Web Development and Technical Support

navigate pages generated from the select query

This is a discussion on navigate pages generated from the select query within the PHP Programming forums, part of the Web Development category; Mentioned below is a PHP function , which can be used to navigate pages generated from the select query . ie. in ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-22-2007, 01:20 AM
hanusoftware hanusoftware is offline
D-Web Trainee
 
Join Date: Jun 2007
Posts: 5
hanusoftware is on a distinguished road
Default navigate pages generated from the select query

Mentioned below is a PHP function , which can be used to navigate pages generated from the select query . ie. in the form of << Previous || Next >>

<?


function PagerNextPrevious(&$sql,$pagesize,$class='txt'){

// Set Default Page Size to 20
if($pagesize=="")
$pagesize=20;
$page=get_post('page');
if($page!='NA'){
$beg=($page-1)*$pagesize;
$end=$pagesize;
}else{
$beg=0;
$end=$pagesize;
$page=1;
}
$rs=mysql_query($sql) ;
$nrows=mysql_num_rows($rs);
$sql=$sql." limit $beg,$end";
$rs=mysql_query($sql);
$subrows=mysql_num_rows($rs);

if($nrows!=0){
$from=(int)($beg)+1;
$totalpages=(int)($nrows/$pagesize);
$frac=($nrows/$pagesize);
if(($frac-$totalpages)>0)
$totalpages+=1;
echo "( Page $page of $totalpages )&nbsp; &nbsp;&nbsp; ";
if($page>1 ){
echo "<a class=$class href='".selfq()."&page=".($page-1)."'> &lt;&lt;Previous </a>";
}
$next=$page+1;
if($next <=$totalpages ){

echo "&nbsp;&nbsp;&nbsp;<a class=$class href='".selfq()."&page=".$next."'> Next &gt;&gt; </a>";
}

}
}

// Assuming you have Opened connection to mysql database.

$sql=" Select * from Products ";

// Show the pager link in form of Previous||Next

PagerNextPrevious($sql,20,'text');

$rs=mysql_query($sql);
if(mysql_num_rows($rs)>0){
while($row=mysql_fetch_array($rs)){
echo $row["ProductName"]."<br>";

}
}




?>

Software Development India
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can anybody tell me, how to select 2nd max salary from table sathian Database Support 3 11-20-2007 02:36 AM
Is it possible to select more than single item in dropdown use Asp.net kingmaker ASP and ASP.NET Programming 4 08-03-2007 09:09 AM
What are the different tables present in mysql, which type of table is generated when oxygen Database Support 2 07-26-2007 03:37 AM
how to post multiple select value through javascript saravanan HTML, CSS and Javascript Coding Techniques 1 07-13-2007 04:53 AM
Deciding who to select for your webdesign makemoneyonlinenow Web Design Help 4 05-17-2007 05:03 AM


All times are GMT -7. The time now is 02:44 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0