Jump to content

updating number


justinh

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.