Non-database dynamic pagination Opinions please

Discussion in 'Programming' started by Colbyt, Jan 7, 2008.

  1. #1
    Scripting a dynamic navigational menu (php) for a non-database site. Using the following menu:

    First | Prev | Viewing 15-of- 16 | Next | Last

    Where:
    First is always the first file in the directory
    Last is always the last file in the directory
    Viewing is not an active link.
    Previous and next work as they should work

    The initial page load is a random file between first and last.

    My question is how would you handle previous when the first file is diplayed?
    And how would you handle next when the last file is displayed?

    Making them non-active seems to be beyond my current skills so the choices seem to be:
    Previous defaults to 1 when 1 is the current file or it loops to last.
    and
    Next defaults to last when last is the current file or it loops to 1.

    Tell me what you think.
     
    Colbyt, Jan 7, 2008 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Dont use PHP so cannot give the exact code but you could create a datatable or array of all the files in a randomised order and then page through them - could hold the array in a session variable or cookie or such
     
    AstarothSolutions, Jan 7, 2008 IP
  3. kevinvd

    kevinvd Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes, thats a possibility
    or just make 1 variable: maxPages (nr of pages) and call your pages like
    0.htm to MaxPages.htm

    and then just randomize a nr and load pageNR.htm on your homepage
    if current page is 0 don't href the 'previous' ancher and if page is same as your maxPages integer, don't href the 'next' ancher.

    don't know PHP but should be something like:

    currentpage = random number
    maxPages=10

    if currentpage > 0
    hrefPrevious=currentPage-1

    if currentPage < maxPages
    hrefNext=currentPage+1

    <a href="%hrefPrevious%"> Go Back </a>
    <a href="%hrefNext%"> Next </a>
     
    kevinvd, Jan 7, 2008 IP
  4. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK, guys, how about this:

    <?php
    if ($current_page != 1)
    {echo "<a href='$first_page_url'>First</a> |";}
    else
    {echo "First |";}
    echo "<a href='$prev_page_url'>Prev</a> |";
    echo " Viewing $page_no -of- $max_pg ";
    echo "| <a href='$next_page_url'>Next</a>";
    if ($current_page != $max_pg)
    {echo "| <a href='$last_page_url'>Last</a>";}
    else
    {echo "| Last";}
    ?>

    PM me if you need further inspiration!
     
    chrissyj, Jan 8, 2008 IP
  5. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Who does that help create a random order of files in a directory Chrissy?
     
    AstarothSolutions, Jan 8, 2008 IP
  6. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hy ther, all! AstarothSolutions, read his original post - he did not ASK for code to create a random order of files - he asked for code that would handle disabling the controls in the case of first and last page. And that's what the code I posted does.
     
    chrissyj, Jan 9, 2008 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I stand corrected, apologies Chrissy
     
    AstarothSolutions, Jan 9, 2008 IP
  8. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #8
    Chrissy

    I have copied that code and will take a look at it a bit later. Whether it works or not Thanks for trying.


    I will followup in this thread.
     
    Colbyt, Jan 9, 2008 IP