Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy only 5 at the time

    Hello

    I created a php script, it will get the info from mysql and display it.

    My question is, I only want to disply 5 records at the time, user have to click next to view 5 more and so on....

    I know how to disply all of them at once, but 5 at the time???

    Can someone please help me.

    Thank you in advance,

    Mike

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is what I do for my forum:

    PHP Code:
    $x 1;
    if(
    $threadAmmount 5)
    {
    echo 
    '<span id="nameDescrip">Pages: </span>';
        if((
    $_GET['start']-5) >= 0)
        {
            echo 
    '<a class="arrows" href="page.php?&start='.($_GET['start']-5).'">&lt;</a>&nbsp;&nbsp;';
        }
        for(
    $i 0$i $threadAmmount$i+=5)
        {
            if(
    $_GET['start'] != $i)
            {
                echo 
    ' &nbsp;<a class="arrows" href="page.php?&start='.$i.'">'.$x.'</a>&nbsp; ';
                
    $x++;
            }
            else
            {
                echo 
    ' <span id="nameHeading">[ '.$x.' ] </span> ';
                
    $x++;
            }
        }
        if((
    $_GET['start']+5) < $threadAmmount)
        {
            echo 
    '&nbsp;&nbsp;<a class="arrows" href="page.php?start='.($_GET['start']+5).'">&gt;</a>';
        }
        

    It passes the start through a variable called start ( $_GET['start']; )

    PHP Code:
    $limit 0;
    $query mysql_query("SOME QUERY");

    for(
    $i 1$row mysql_fetch_array($query); $i++)
    {
       if(
    $limit >= 5)
       {
       break;
       }
       else
       {
       if(
    $i == && $i == $_GET['start'] || $i $_GET['start'])
       {
                
    // Do Whatever with the info
                
    $limit++;
       }
       }

    That makes sure you only display the files wanted.

    This system also makes a next and back system like on my forum

    [ 1 ] 2 3 4 >


    Hope this helps.


  •  

    Posting Permissions

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