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
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PHP Increment/Decrement

    This might sound a bit noobish but I am having trouble creating a increment/decrement button. So basically, I created a website that uses Tumblr feed to view photos that I've tagged. For example, if I pass a variable called "nav" that equals california, it will show all of my photos from california by using this code.

    Code:
    <?php
    $location = $_GET['nav'];
    echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["nav"] . "/js' type='text/javascript'></script>";
    ?>
    But the problem I am having is that it only shows the first 10 photos and in order for me to view the next page I have to add this into the code.

    Code:
    <?php
    $location = $_GET['nav'];
    echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["nav"] . "/page/2/js' type='text/javascript'></script>";
    ?>
    And so on...

    I want to be able to add a button to change the variable after "page/". And another thing is, the first page cannot read "page/1", because when I do it doesn't show anything. So the first page has to be the first script, and then after they press a "next" button, it has to go to the second code. I've gotten this so far:

    Code:
    <?php
    $location = $_REQUEST['nav'];
    $page = $_POST['page'];
    if (isset($_POST['next']))
    {
       $page++;
    }
    else if (isset($_POST['previous']))
    {
       $page--;
    }
    
    if ($page <= 1)
    {
       echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "/js' type='text/javascript'></script>";
    }
    else
    {
       echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "page/" . $page . "/js' type='text/javascript'></script>";
    }
    ?>
    
    <form method="POST">
    <input type="hidden" name="navigation" value="location" />
    <input type="submit" name="previous" value="previous">
    <input type="submit" name="next" value="next">
    <input type="hidden" name="navigation" value="<?php echo $location; ?>" />
    </form>
    But nothing seems to work /:

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Post data are strings, so convert to an integer before attempting to inc/decrement:

    $page = intval($_POST['page'], 10);

    but you should use an is_numeric() test first.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

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