pagination help please

Discussion in 'PHP' started by nQQb, Jul 8, 2008.

  1. #1
    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">&nbsp;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">&nbsp; 
                      <?php 
    						if($npytype == 1)
    						{	?>
                     <?php echo substr( $npyrow_koj["npykoje_text"], 0 , 150 ); ?>&nbsp;...&nbsp;&nbsp;<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"]; ?>
                        &nbsp;</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>&nbsp;&nbsp;Pages: 
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <?php
    if ($pg>1) 
    {
    ?><a href="searchresult.php?pg=<?php echo ($pg-1).$npystrpass; ?>" class="pagingstyle"><?php
    }//end if
    if ($pages<>1)
    echo "&nbsp;&nbsp;Previous";
    if ($pg>1)
    {
    ?></a><?php
    }//end if
    echo "&nbsp;&nbsp;";
    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 '&nbsp;&nbsp;';
    }//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:
     
    nQQb, Jul 8, 2008 IP
  2. nQQb

    nQQb Active Member

    Messages:
    332
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    no one wants to help? :(
     
    nQQb, Jul 9, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    EricBruggema, Jul 12, 2008 IP