SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Thread: Previous / Next

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Previous / Next

    Is there a way to go to the next or previous static HTML page by just clicking on next or previous? I know in PHP you can do it with MySql and a database but I haven't been able to find any thing that will work with static HTML pages.

    Thanks,

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    previous next links

    Page 1
    HTML Code:
    ....
    <a href='page2.html'>Next</a>
    ....
    Page 2
    HTML Code:
    ....
    <a href='page1.html'>Previous</a> | <a href='page3'>Next</a>
    ....
    Page 3
    HTML Code:
    ....
    <a href='page2.html'>Previous</a> | <a href='page4'>Next</a>
    ....
    etc. etc.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done that before. If I delete a page for some reason then I have to go back and change all the pages. I was hoping there would be an easier way..

    Thanks

  4. #4
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    There isn't. That's why it's called static
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  5. #5
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)
    Why do you wanna do it the static way?

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I am doing. I am setting up a website for a friend and he will have two pages of 20 images of the items he is selling. He will be using PayPal for his shopping cart. One page will have 20 images. You can click on an image and it takes you to a page with a larger image and information about it. What I would like to do is have Previous and Next links to go to the next item without having to go back to the main page.

    If I do this below and he eliminates the second item then we have to go in and change the other 18 pages.

    HTML Code:
    <a href='page1.html'>Previous</a> | <a href='page3'>Next</a>

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    links to transient pages

    This could be done with an external javascript file holding an array. Then you would only need to edit the 1 file. BUT, for users without javascript and for search engines the pages would be inaccessible (essentially non-existent) unless links were also hard-coded (so ... problem not eliminated).
    The server doesn't have any scripting language available? No PHP? Perl CGI?
    If the server only has HTML and you are planning on having an e-business site, IMHO you should invest in a better host.

  8. #8
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree. Ditch your hosting provider and get another one.

    Also, if you're going to be using a previous and next link setup like that, I'd use an unordered list.

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can it be done using PHP without using a database?

  10. #10
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by denny View Post
    Can it be done using PHP without using a database?
    certainly

    just hardcode the page numbers/filenames rather than getting them from the database
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  11. #11
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok.. I'll give that a try..

    Thanks,

  12. #12
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    previous next

    Although there are lots of benefits with using a database, you can use PHP for <- | -> links easy enough. I would use an array something like
    PHP Code:
    /* edit to reflect changes */
    $pages = array('widgets''sprockets''cogs''foos''bars'); 
    in an include file,
    Then use PHP to create the previous next numbers
    PHP Code:
    $this_page 'cogs';/* 'hard-coded' per page */
    $this_page_num array_search($this_page$pages);
    $previous_num $this_page_num 1;
    $previous $pages[$previous_num];
    $next_num $this_page 1;
    $next $pages[$next_num];
    ......
    echo 
    "<a href='" $previous ".html '>Previous</a>";
    echo 
    "<a href='" $next ".html '>Next</a>"
    Of course you would need to have 'first page - last page' tests, and typos would break it, but hopefully you get the idea.

  13. #13
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This worked great.... Thank you..

    There is one thing. I would like to separate the words previous and next. I have tried several different ways to move the word "next" to the right side of the page. Which I am able to do. However, no matter what I do it moves the word "next" down a line.

    How can I keep the word "previous" on the left side of the page and the word "next" on the right side but keep them on the same line?

    Thanks,

  14. #14
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    styling

    CSS can be a bit tricky and frustrating at times, especially when trying to get good cross-browser, cross-version, variably-sized-viewport rendering.
    Without seeing your existing mark-up and CSS I can only guess, but maybe using float: left, float: right ???

  15. #15
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I havn't even gotten to the CSS for this snippet of code yet. I built the array and then I have this code. When I put the "div align='right'" in the echo command the word "Next" moves to the right side of the page but it is no longer on the same line as the word "Previous". It is a line below it. When I use p align='right' it drops it two lines. How would I keep it on the same line?

    PHP Code:
    <?php
     $this_page 
    '103_Boston_Terrier';/* 'hard-coded' per page */
     
    $this_page_num array_search($this_page$pages);
     
    $previous_num $this_page_num 1;
     
    $previous $pages[$previous_num];
     
    $next_num $this_page_num 1;
     
    $next $pages[$next_num];
     echo 
    "<a href='" $previous ".php '>Previous</a>";
     echo 
    "<a href='" $next ".php ' ><div align='right'>Next</div></a>";
    ?>
    I have tried combining the echo statement and it still drops the "Next" down a line.
    PHP Code:
    echo "<a href='" $previous ".php '>Previous</a>""<div align='right'><a href='" $next ".php ' >Next</a></div>"

  16. #16
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    block element

    A div is a 'block" element, so browsers want to not display it "inline".
    Maybe put both links inside the div, and use inline tags (spans ?) to align left and right.

  17. #17
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I finally got it to work. What I did was create a table with two cells side by side. I put the last line that prints out the "Next" and put it by itself in the second cell. I aligned that cell to the right.

    PHP Code:
     <table border="0" width="754" align="center" cellpadding="0" cellspacing="0">
      <tr>
       <td width="754">
    <?php
     
    /* edit to reflect changes */ 
     
    $pages = array('101_Akita''102_Basset_Hound''103_Boston_Terrier''104_Chihuahua''105_Chihuahua''106_Cocker_Spaniel''107_Collie''108_Dachschund''109_Dachschund''201_French_Bulldog''202_German_Shorthair''203_Jack_Russell''204_Labrador''205_Pitbull''206_Pitbull''207_Pomeranina''208_Poodle''209_Rhodesian_Ridgeback''301_Scottish_Terrier''302_St_Bernard');
    ?>
    <?php
     $this_page 
    '103_Boston_Terrier';/* 'hard-coded' per page */
     
    $this_page_num array_search($this_page$pages);
     
    $previous_num $this_page_num 1;
     
    $previous $pages[$previous_num];
     
    $next_num $this_page_num 1;
     
    $next $pages[$next_num];
     echo 
    "<a href='" $previous ".php '>Previous</a> ";
    ?>
       </td>
       <td align="right">
    <?php
     
    echo "<a href='" $next ".php '>Next</a>";
    ?>
       </td>
      </tr>
     </table>
    Right or wrong it works.. Using span did not work..

    Will this cause problems?

    Thanks again,

  18. #18
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really. However bear in mind that this is not tabular data, which is why I suggested an unordered list instead (give the list an ID, something like "previous-next" for example) since what you have is a list of links (albeit a VERY small list).

    Then in the stylesheet set the height and line height on the list (plus kill the list bullet markers), then set the list items to display: inline and white-space: nowrap; and float the links inside them to the left, setting a height on the anchors to deal with IE.


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
  •