Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-02-2012, 10:40 PM   PM User | #1
jadeallencook
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jadeallencook is an unknown quantity at this point
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 /:
jadeallencook is offline   Reply With Quote
Old 12-03-2012, 12:16 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:16 PM.


Advertisement
Log in to turn off these ads.