Passing an incremental variable into a URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfman
    New Member
    • Apr 2007
    • 21

    Passing an incremental variable into a URL

    Hi guys

    I have a subdomain with 79 individual episode pages, and I'd like to create a "Next >>" link that reads the number included in the top page name, then adds a value of one, sending the user to the next higher-numbered page within the acceptable range of 01 to 79. Page 79 would wrap back to page 01. This would allow the user to move incrementally while I continue to use a single, embedded navigation page for all episodes.

    For example, each page is ep01.html, ep02.html through ep79.html. The embedded navigation page works by targeting "_top" in each link. If the user is on page ep27.html clicks "Next Episode >>" in the navigator they load ep28.html. However, if the user is on page 79, they load ep01.html because they are at the end of the page range.

    Here's the full URL of page one:
    http://series.airwolf. tv/episodes/ep01.html
    and the pending embedded navigator page:
    http://series.airwolf. tv/episodes/epguidefinder.h tml
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Wolfman.

    You can use the $_SERVER['PHP_SELF'] variable to find out the name of the current file, and use that to find out what the next file should be.

    Something like:
    [code=php]
    # Get the current file name and index of the next file
    $currentName = basename($_SERV ER['PHP_SELF'], ".html");
    $currentIndex = substr($current Name, -2);
    $nextIndex = $currentIndex + 1;

    # Make sure the index is not higher than 79
    if($nextIndex > 79)
    $nextIndex = 0;

    # Prefix the number with a 0 if it is less than 10
    if($nextIndex < 10)
    $nextIndex = "0". $nextIndex;

    # Print the link
    echo "<a href=\"ep{$next Index}.html\">N ext</a>";
    [/code]

    Comment

    • Wolfman
      New Member
      • Apr 2007
      • 21

      #3
      Tried it, but one hitch remains

      Thanks. I added target=\"_top\" into the href since the link must call the parent window, but other wise embedded it as-is:

      [PHP] <?php
      # Get the current file name and index of the next file
      $currentName = basename($_SERV ER['PHP_SELF'], ".html");
      $currentIndex = substr($current Name, -2);
      $nextIndex = $currentIndex + 1;

      # Make sure the index is not higher than 79
      if($nextIndex > 79)
      $nextIndex = 0;

      # Prefix the number with a 0 if it is less than 10
      if($nextIndex < 10)
      $nextIndex = "0". $nextIndex;

      # Print the link
      echo "<a href=\"ep{$next Index}.html\" target=\"_top\" >Next Episode >></a>";
      ?>[/PHP]

      However, each time the link is clicked, it returns to page 01 only. Check it out by selecting any of the first five episodes here:



      You'll see the resulting "next episode>>"link in the little navigator window on the left.

      Wolfman
      Last edited by Wolfman; Dec 10 '07, 03:18 AM. Reason: Code was shown as plain text

      Comment

      • robin1983
        New Member
        • Oct 2007
        • 99

        #4
        I gone through of your code, and i think the problem is in line
        [PHP]
        echo "<a href=\"ep{$next Index}.html\" target=\"_top\" >Next Episode >></a>";
        [/PHP]

        if possible plz try like this
        [PHP]
        echo "<a href=\"ep.{$nex tIndex}.html\" target=\"_top\" >Next Episode >></a>";
        [/PHP]
        ok best of luck ..

        Originally posted by Wolfman
        Thanks. I added target=\"_top\" into the href since the link must call the parent window, but other wise embedded it as-is:

        [PHP] <?php
        # Get the current file name and index of the next file
        $currentName = basename($_SERV ER['PHP_SELF'], ".html");
        $currentIndex = substr($current Name, -2);
        $nextIndex = $currentIndex + 1;

        # Make sure the index is not higher than 79
        if($nextIndex > 79)
        $nextIndex = 0;

        # Prefix the number with a 0 if it is less than 10
        if($nextIndex < 10)
        $nextIndex = "0". $nextIndex;

        # Print the link
        echo "<a href=\"ep{$next Index}.html\" target=\"_top\" >Next Episode >></a>";
        ?>[/PHP]

        However, each time the link is clicked, it returns to page 01 only. Check it out by selecting any of the first five episodes here:



        You'll see the resulting "next episode>>"link in the little navigator window on the left.

        Wolfman

        Comment

        • Wolfman
          New Member
          • Apr 2007
          • 21

          #5
          Thank you robin1983. I changed the line, but regretfully the chage results in an extra period being placed in the page name, but it still defaults to #01 each time. Further thoughts?

          Wolfman

          Comment

          • Wolfman
            New Member
            • Apr 2007
            • 21

            #6
            I echoed each variable individually and came up with this:

            $currentName = epguidefinder.p hp
            $currentIndex = hp
            $nextIndex = 01

            Remember that this script is running on a single page that is loaded within each parent HTML page. The benefit of a working script is that it senses the page it is loaded into, so a single instance serves all.

            The embedded page is always called epguidefinder.p hp, so right now the script is detecting the page it's placed on, not the one it's embedded within.
            Therefore it's taking the "hp" from "php" and making that the currentIndex variable.
            So nextIndex is hp+1, which results in ep01.html every time.

            Problem is, I'm not sure how to resolve the code.
            First, it must sense the "_top" window, not itself
            Second, it must truncate the filename without the .html like it currently did with the .php extension.

            Comment

            • Wolfman
              New Member
              • Apr 2007
              • 21

              #7
              Solved it!

              I used HTTP_REFERER instead of PHP_SELF.

              Thanks everyone for your help!

              Wolfman

              Comment

              Working...