Jump to content

Recommended Posts

This has been a problem I havn't yet quite grasped how to do in PHP.

 
<?php 
$number = 1; 

if(isset($_GET['direction'])){ 
    if($_GET['direction'] == 1){
     $prevnumber = $number - 1;	
 echo "<a href=\"testing.php?direction=1\">prev </a>".$prevnumber."<a href=\"testing.php?direction=2\">next </a>";
 } 

 if($_GET['direction'] == 2){
 $nextnumber = $number + 1; 
 echo "<a href=\"testing.php?direction=1\">prev </a>".$nextnumber."<a href=\"testing.php?direction=2\">next </a>"; 
 } 
}else{ 
   echo "<a href=\"testing.php?direction=1\">prev </a>".$number. "<a href=\"testing.php?direction=2\">next </a>"; 
   
   }
   ?>

 

How would I go about making a number continually increase or decrease ( depending on what link is clicked)?

 

It works the first time but that's pretty much it. 

Link to comment
https://forums.phpfreaks.com/topic/138778-updating-number/
Share on other sites

I would do it in Javascript.  But if it must be PHP:

 

<?php
$number = isset($_GET['number']) ? $_GET['number'] : 1; 

if (isset($_GET['direction']))
{ 
if ($_GET['direction'] == 'up')
{
	$number++;   
} 
else if ($_GET['direction'] == 'down')
{	
	$number--;
} 
}
?>
<a href="?direction=up&number=<?php echo $number ?>">up</a>
<?php echo $number ?>
<a href="?direction=down&number=<?php echo $number ?>">down</a>

Link to comment
https://forums.phpfreaks.com/topic/138778-updating-number/#findComment-725629
Share on other sites

thanks for your help :)

 

Here's me applying what you taught me :)

 

 
<?php 

$alphabet = range('a','z'); 

if(isset($_GET['letter'])){ 

$letter = $_GET['letter'];

}else{ 


$letter = 0; 

}

if(isset($_GET['direction'])){ 

    if($_GET['direction'] == up){
     $letter = $letter + 1; 
     } else {
     $letter = $letter - 1; 

}

}

echo "<a href=\"testing.php?letter=".$letter."&direction=down\">prev</a> " .$alphabet[$letter]. " <a href=\"testing.php?letter=".$letter."&direction=up\">next</a>"; 

?>

Link to comment
https://forums.phpfreaks.com/topic/138778-updating-number/#findComment-725655
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.