Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: limiting results

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Posts
    755

    limiting results

    Hi all:

    I have my sitemap organized by product name. Needless to say this gets longer the more products I add to my database. Can some one please tell me how I can limit the results per page? I tried it earlier and got it to display the first page correctly but not the other pages.

    Here is the page as it currently stands

    http://www.jacksretail.com/online-sh...es-sitemap.php

  2. #2
    Senior Member redcircle's Avatar
    Join Date
    Aug 2003
    Posts
    424
    You can accomplish this by using a limit in the sql statement.

    Code:
    if(!isset($_GET['page']))
    {
      $page = 1;
    }
    else
    {
    $page = $_GET['page'];
    }
    $query = 'select * from products limit '.$page.',10';
    then for the next/previous buttons you just add $page+1 and $page-1 to the url of the link.

    If you need some more help let me know.
    www.squitosoft.com - PHP development site. featuring Squito Gallery. a php driven photo gallery.
    www.rgfx.net - Specializing in Internet solutions, including Html authoring, Interactive Web sites, 3D/2D Graphics and animation.

  3. #3
    Senior Member
    Join Date
    Sep 2003
    Posts
    755
    Thx:

    I'm still having trouble with this part. Did I do something wrong?

    start of code:
    ------------------------------------

    <?

    if($page != 1){
    $pageprev = $page-1;
    }

    echo("<a href=\"jackscategories.php?$page=$pageprev\">PREV</a> ");

    $numofpages = $totalrows / $limit;
    for($i = 1; $i <= $numofpages; $i++){
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"jackscategories.php?$page=$i\">$i</a> ");
    }

    if(($totalrows % $limit) != 0){
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");
    }

    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page+ 1;
    echo("<a href=\"jackscategories.php?page+1=$pagenext\">NEXT </a>");
    }else
    echo(" NEXT ".$limit);
    mysql_free_result($result);
    ?>


    It's giving me the following error message:

    Warning: Division by zero in /home/wwwjack/public_html/online-shopping-at-discount-prices-sitemap.php on line 215

  4. #4
    Senior Member httpman's Avatar
    Join Date
    Aug 2003
    Posts
    121
    Hello.

    Your code is not so clear.
    You make a reference to $pageprev in the first block, and the way you use it is OK, but then you put an echo statement - but what happens if $page is not != 1 ?
    $pageprev should be initialised to $page - I guess you did it, but you forgot to tell it in this post.


    Note : the fictitious 'www' links above will show a link, but they don't go anywhere !.. Just type 'www.' in this post and you will display a link. I just put those words as an example, there is no target to "www.blabla" as you can easily imagine !!!

    What makes me answering this post is your PREV / NEXT links at the bottom of your web page. It show this information :
    * prev : www.blabla.php?1-1=
    * next : www.blabla.php?1+1=

    What are those ?1-1=' and '?1+1=' parameters ? This is not the good way to send 'post' parameters. You should use that way :

    * prev : www.blabla.php?page=z
    * next : www.blabla.php?page=z

    Where z is the page number you want to go to. Then in the target page, you can easily catch the "$page" value (as your parameter is called "?page=") via that line :

    foreach($HTTP_POST_VARS as $name=>$value) $$name=$value;

    If you need more parameters, you can use that way :

    www.blabla.php?param1=xxx&param2=yyy&param3=zzz

    Then after using the "foreach" line above, you get a $param1, $param2 and $param3 set of variables.

    Then, back to your issue : using that way to send & catch parameters, you can easily use a "$page" wich is very to use in any SQL limit script.

    JP
    www.net-createurs.com [ french only website sorry ! ]

  5. #5
    Senior Member
    Join Date
    Sep 2003
    Posts
    755
    ok I see what you say I did. After that you completely lost me. It should be possible to somehow do it with my code, no? Your way is very confusing to me LOL

  6. #6
    Senior Member redcircle's Avatar
    Join Date
    Aug 2003
    Posts
    424
    Code:
    <?
    $limit=20;
    if($page != 1){  
            $pageprev = $page-1; 
    }
    
    echo("<a href=\"jackscategories.php?page=$pageprev\">PREV</a> "); //removed $ in front of page
    
    $numofpages = $totalrows / $limit;  
    for($i = 1; $i <= $numofpages; $i++){ 
    if($i == $page) 
                echo($i." ");  
            else 
                echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");  //removed $ in front of page
    }
    
    if(($totalrows % $limit) != 0){ 
    if($i == $page) 
                echo($i." "); 
            else 
                echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");
    }
    
    if(($totalrows - ($limit * $page)) > 0){ 
    $pagenext    = $page+ 1; 
    echo("<a href=\"jackscategories.php?page=$pagenext\">NEXT</a>");  //removed +1 after page
    }else 
            echo("  NEXT ".$limit);  
    mysql_free_result($result); 
        ?>
    It would only give you a division by zero error if the $limit variable is not defined. also there is a little problems with the code that i fixed. read the comments.
    www.squitosoft.com - PHP development site. featuring Squito Gallery. a php driven photo gallery.
    www.rgfx.net - Specializing in Internet solutions, including Html authoring, Interactive Web sites, 3D/2D Graphics and animation.

  7. #7
    Senior Member
    Join Date
    Sep 2003
    Posts
    755
    Thx Red:

    I almost have it. The only thing wrong now is it's not hyperlinking the Next. Almsot like the pages don't exist?

    http://www.jacksretail.com/online-sh...s-sitemap.phps

    Is something wrong somewhere else in my script?

  8. #8
    Senior Member redcircle's Avatar
    Join Date
    Aug 2003
    Posts
    424
    You are not assigning $totalrows a value.

    After the $result = mysql_query($query) set the totalrows.

    $totalrows = mysql_num_rows($result)
    www.squitosoft.com - PHP development site. featuring Squito Gallery. a php driven photo gallery.
    www.rgfx.net - Specializing in Internet solutions, including Html authoring, Interactive Web sites, 3D/2D Graphics and animation.

  9. #9
    Senior Member
    Join Date
    Sep 2003
    Posts
    755
    I must be slow because I did that and am still not getting the next to hyperlink

  10. #10
    Senior Member
    Join Date
    Sep 2003
    Posts
    755
    Update:

    I fanlly got the pages to display as links. Unfortunately it's showing the whole query on the other pages. That is it's not limiting the other pages and the layout looks totally different

Page 1 of 2 12 LastLast

Similar Threads

  1. Google's New 'Add Results, Promote Results, Delete Results. Question?
    By OpticBurst.com in forum Google Discussion Forum
    Replies: 4
    Last Post: 01-07-2009, 02:22 AM
  2. Replies: 18
    Last Post: 12-20-2008, 12:15 PM
  3. Limiting Your Search By IP Address with MSN Search and Giga
    By WPW_Feedbot in forum Search Engine Optimization Forum
    Replies: 0
    Last Post: 01-10-2006, 11:00 AM
  4. Apple Limiting AdWords In Europe Only?
    By jmiller in forum Google AdWords/Google AdSense
    Replies: 0
    Last Post: 10-05-2005, 04:05 PM
  5. Updated Yahoo! Search Limiting Parameters
    By ronniethedodger in forum Yahoo! Discussion Forum
    Replies: 5
    Last Post: 10-04-2004, 01:57 PM

Posting Permissions

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