justinh Posted December 29, 2008 Share Posted December 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138778-updating-number/ Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 You need to store it somewhere. Either use another $_GET variable or store it in a hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/138778-updating-number/#findComment-725628 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/138778-updating-number/#findComment-725629 Share on other sites More sharing options...
justinh Posted December 29, 2008 Author Share Posted December 29, 2008 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138778-updating-number/#findComment-725655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.