pooker Posted June 19, 2008 Share Posted June 19, 2008 Alright i appreciat your guys helps and fast responses. , as you can see, there is a submit button and when clickt it invokes the php if statement at the top, well of course when you click next I want it to go to the next image, so I used number to increase but it is not increasing the number to change the image, does anyone know why? <?php if(isset($_POST['submit'])) { $number=$number +1; } $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); echo 'You are on page '. $number . ' of ' . $images; ?> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <input type="submit" name="submit" value="Next"> </form> </br> <? echo "<img src=\"./mangareader/bleach/chapter1/$number.png\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/ Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 Where is $number getting its value? When u click submit, it reloads the page. All the variables will be reset. You might want to set a hidden form value with the current number and then increment that. Dan Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-568789 Share on other sites More sharing options...
pooker Posted June 19, 2008 Author Share Posted June 19, 2008 I was confused about that when reading up on it, do you think you could explain how I could do that? Also here is something I am wondering if could work? Th only problm is thinking how to change that value on on click like when it refreshes the page i use the get to store the value from the url, but then I need to put that value back in the link. <?php $value= $_GET['Next'] $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); echo 'You are on page '. $value . ' of ' . $images; ?> <input type="submit" name="submit" value="Next" onclick="window.location.href=page.php?Next=(value);"> </br> <? echo "<img src=\"./mangareader/bleach/chapter1/$value.png\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-568845 Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 That's more or less what I was getting at. However, you will need to increment value so that you always go to the next photo and not the same one over and over again. I'm not a big fan of $_GET, so I would do it like this: <?php $value = $_POST['value'] $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); //Somewhere in here you need to actually show the image, correct? echo 'You are on page '. $value . ' of ' . $images; ?> //You will pass newValue back through the hidden form field and that will be the next picture. $newValue = $value++; ?> <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="value" value="<?php print $newValue; ?>" /> <input type="submit" name="submit" value="Next"> </form> </br> <?php echo "<img src=\"./mangareader/bleach/chapter1/$value.png\">"; ?> HTH Dan Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569121 Share on other sites More sharing options...
xyn Posted June 19, 2008 Share Posted June 19, 2008 with your code you could try: <?php $number =$_GET['number']; if($number) $number +=1; $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); print "You are on page $number of $images"; ?> <form action="?number=<?=$number?>" method="post"> <input type="submit" name="submit" value="Next"> </form> </br> <img src="./mangareader/bleach/chapter1/<?=$number?>.png"> Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569126 Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 You still need to increment $number or it will keep linking to the same pic. Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569140 Share on other sites More sharing options...
xyn Posted June 19, 2008 Share Posted June 19, 2008 Ok, i tested this, and it works... <?php $number =$_GET['number']; $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); print "You are on page $number of $images"; ?> <form action="?number=<?=$number+1?>" method="post"> <input type="submit" name="submit" value="Next"> </form> </br> <img src="./mangareader/bleach/chapter1/<?=$number?>.png"> Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569148 Share on other sites More sharing options...
pooker Posted June 19, 2008 Author Share Posted June 19, 2008 wow thank you man so much I am learning so much in my first week, I didn't realise you could increment a variable in an action like that, that makes things so much more easier. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569575 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Ok, i tested this, and it works... <?php $number =$_GET['number']; $dir = './mangareader/bleach/chapter1/'; $images = count(glob("$dir{*.jpg,*.JPG,*.png}", GLOB_BRACE)); print "You are on page $number of $images"; ?> <form action="?number=<?=$number+1?>" method="post"> <input type="submit" name="submit" value="Next"> </form> </br> <img src="./mangareader/bleach/chapter1/<?=$number?>.png"> Except don't use short tags. =/ Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569577 Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 Technically he's not incrementing the variable, he's sending the value of the variable plus one. But anyhow. And like DarkWater said, don't use short tags. Dan Quote Link to comment https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/#findComment-569626 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.