Hi, I was wondering if a php pro can help me out here.... Currently this code is showing so many pagination but I want to limit it to max 10 at a time and have next 10 link. here's the code: Hi, I was wondering if a php pro can help me out here.... Currently this code is showing so many pagination but I want to limit it to max 10. here's the code: [PHP]<?php ///////////////////////////actual query here if($npytype == 1) { $npyquery_koj="SELECT *,DATE_FORMAT((npysubmit_date),'%d, %b %Y') as npy_date, npyscore/npyno_of_ratings as score FROM `npyjks_kojes` WHERE 1 $npykeyword_str $npyindex_str $npycat_str $npyrating_str and npyapproved='yes' ORDER BY score desc, npysubmit_date desc"; } else { $npyquery_koj="SELECT *,DATE_FORMAT((npysubmit_date),'%d, %b %Y') as npy_date, npyscore/npyno_of_ratings as score FROM `npyjks_pictures` WHERE 1 $npykeyword_str $npyindex_str $npycat_str $npyrating_str and npyapproved='yes' ORDER BY score desc, npysubmit_date desc"; } // die($npyquery_koj); $npyrs_koj=mysql_query($npyquery_koj); ////---------------------------------PAGING BEGINS -------------------------- $rcount=mysql_num_rows($npyrs_koj); if($rcount <= 0) { //no records found then stop ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="100%" height="25" class="maintablestyle"> No match found satisfying your search criteria.</td> </tr> </table> <?php } // end if no records found else { //records found $recperpage=$npyrec_per_page_db; if ($rcount==0 ) $pages=0; else { $pages=floor($rcount / $recperpage); if (($rcount%$recperpage) > 0 ) $pages=$pages+1; } $jmpcnt=1; while ( $jmpcnt<=($pg-1)*$recperpage && ($npyrow_koj=mysql_fetch_array($npyrs_koj)) ) { $jmpcnt = $jmpcnt + 1; } //die($npystrpass); ////---------------------------------PAGING -------------------------- ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <?php //$npyquery_koj="SELECT *,DATE_FORMAT((npysubmit_date),'%d, %b %Y') as npy_date, npyscore/npyno_of_ratings as score FROM `npyjks_kojes` WHERE 1 $npycat_str ORDER BY score desc, npysubmit_date desc"; $npyrcount=0; while( ($npyrow_koj=mysql_fetch_array($npyrs_koj)) && ($npyrcount < $npyrec_per_page_db) ) { $npyrcount++; ?> <tr valign="top"> <td width="70%" height="30" class="maintablestyle"> <?php if($npytype == 1) { ?> <?php echo substr( $npyrow_koj["npykoje_text"], 0 , 150 ); ?> ... <a href="index.php?<?php echo "npykoje_id=".$npyrow_koj["npykoje_id"]; ?>"><img src"images/read.gif" border="0" valign="middle"></a> <?php } else { ?> <a href="popup.php?<?php echo "npypic_id=".$npyrow_koj["npypic_id"]; ?>" target="_other"><?php echo $npyrow_koj["npypic_text"]; ?></a> <?php } //end else ?> </td> <td width="10%" class="maintablestyle"><div align="right"> <?php $npyno_of_stars=$npyrow_koj["score"]; for($npyi=1;$npyi<=$npyno_of_stars;$npyi++) echo '<img src="images/star1.gif" width="8" height="7">'; for(;$npyi<=5;$npyi++) echo '<img src="images/star2.gif" width="8" height="7">'; ?> </td> <td width="10%" class="maintablestyle"><div align="right"> <?php //echo $npyno_of_stars.", ".$npyrow_koj["score"]; echo $npyrow_koj["npy_date"]; ?> </div></td> </tr> <?php } //end while $npyrow-koj ?> </table> <?php } //end else records found ?> </td> </tr> </table></td></div> </tr> <tr> <td width="50%" class="pagingstyle"><strong> Pages: <?php if ($pg>1) { ?><a href="searchresult.php?pg=<?php echo ($pg-1).$npystrpass; ?>" class="pagingstyle"><?php }//end if if ($pages<>1) echo " Previous"; if ($pg>1) { ?></a><?php }//end if echo " "; for ($i=1; $i<=$pages; $i++) { if ($pg<>$i) { ?><a href="searchresult.php?pg=<?php echo $i.$npystrpass; ?>" class="paginstyle"><?php }//end if echo $i; if ($pg<>$i) { ?></a><?php } echo ' '; }//for if ($pg<$pages ) { ?><a href="searchresult.php?pg=<?php echo ($pg+1).$npystrpass; ?>" class="pagingstyle"><?php }//end if if ($pages<>1) { ?>Next<?php }//end if if ($pg<>($pages)) { ?></a><?php }//end if ?> PHP:
You need to do two queries! one with only COUNT(ID) for max pages and the other for showing items. There are many free page navigation classes. http://www.google.nl/search?hl=nl&q=page+navigation+class+php&meta=