Jump to content

Recommended Posts

Alright i appreciat your guys helps and fast responses.  ;D, 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\">";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/110858-update-numbers-with-if-statement/
Share on other sites

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\">";

 

?>

 

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

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">

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">

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. =/

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.