SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Shropshire, UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with Paging

    Hi,
    I have a number of issues trying to get my paging to work to only display 3 database records per page.

    The issue I'm having is that I can't get my links to the next pages to work.

    This is my php code to work out the paging:
    HTML Code:
    $articleloopquery="SELECT * FROM `articles` WHERE section_id= '".$id."' AND status = 'Live' AND art_type = '1' ORDER BY `publish_date` ASC";
    
    $articleloopresult=mysql_query($articleloopquery) 
        
    
    $articles_page=3;
    if (!$pager) { $pager = 1; $pagera = 0; } else { $pagera = ($pager * $articles_page) - $articles_page; }
    $reccount=mysql_num_rows($articleloopresult);
    $articleloopquery.=" LIMIT ".$pagera.",$articles_page";
    $articleloopresult=mysql_query($articleloopquery);
    
     ?>
    and this is my code to show the page links:

    HTML Code:
    <? if(mysql_num_rows($articleloopresult)!=0){ 
    
    /// pager
    
    ?>
    <div align="right" style="clear:both; margin-right:10px">
    	<p>page: 
    	<? $prevp=$pager-1; $nextp=$pager+1; 
    		if ($prevp>0){ 
    		?>
            	<a href="detail_page.php?id=<?=$_GET['id']?>&amp;pager=<?=$prevp?>" style="font: bold 8pt verdana; color: #1360c2">&laquo; previous</a> 
    	<? } 
    	$pages = ceil($reccount / $articles_page) + 1; 
    		for ($i = 1; $i < $pages; ++$i) {
    			if ($i == $pager){
    				echo " <span style=\"font: bold italic 9pt verdana; color: #0a57a4\"><u>$i</u></span> ";
    			} else { ?>
                	<a href="detail_page.php?id=<?=$_GET['id']?>&amp;pager=<?=$i?>" style="font: bold 8pt verdana; color: #0a57a4"><?=$i?></a>
    		<? }
    		} if ($nextp<$pages){?> 
            	<a href="detail_page.php?id=<?=$_GET['id']?>&amp;pager=<?=$nextp?>" style="font: bold 8pt verdana; color: #0a57a4">next &raquo;</a>
    		<? }?>
    	</p>
    </div>
    <? } ?>
    You can view the page here:
    http://www.client-bevivid.co.uk/simp...page.php?id=14

    Can anyone shed any light on this? I know that my SQL is correct and the amount of articles displayed per page is correct its just the links don't seem to work.

    Thanks
    Kirsty

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Kirsty,

    I don't see anything wrong just glancing over it real quick. Do you have a call to define pager anywhere? Try adding:
    PHP Code:
    $pager=$_REQUEST['pager']; 
    Add this above your line: $articles_page=3;

    Post back if it's still not working. Sometimes we overlook the smallest things.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Shropshire, UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant, that worked!

    Thanks

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than using $_REQUEST,if you are sure that the pager value will come from query string then go for $_GET and if the pager value may come from others too then check them $_POST.
    PHP Code:
    if(isset($_GET['pager'])){
        
    $pager $_GET['pager'];
    }
    elseif(isset(
    $_POST['pager'])){
        
    $pager $_POST['pager'];
    }
    else{
        
    $pager null;

    Since the use of $_REQUEST is discoursed for security issues.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •