Variable passed incorrectly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Catz
Forum Newbie
Posts: 8
Joined: Wed Dec 15, 2004 4:08 pm

Variable passed incorrectly

Post by Catz »

Hi All!

I have the following php code in a form:

Code: Select all

$Limit = 1;
$Page = $_REQUEST["Page"];
if(empty($Page)) {$Page = 1; }
	
$Start = $Page / $Limit - 1;
if($Start <= 1) {$Start = 0;}

$list = mysql_query("SELECT * FROM detail LIMIT $Start, $Limit") or die(mysql_error());
$num = mysql_num_rows($list);
$rows = $num / $Limit;
$next = $Page * $Limit;
...

Code: Select all

if($Page > 1) {
$p = $Page - 1;
?>

<input type="hidden" name="Page" value="<?php echo $p; ?>">
<input type="submit" name="Submit" value="Previous">

<?php
if($next < $rows) {
$f = $Page + 1;
?>

<input type="hidden" name="Page" value="<?php echo $f; ?>">
<input type="submit" name="Submit" value="Next"><?php }
The "next" button works fine, but the "previous" button acts weird. When pressed the first time, eg on page4, it will go to page 3. When pressed again on page3, it goes back to page 4....? I've added
<?php print $p; ?> and <?php print $Page ?> - $p outputs the correct page number : 2, but when submitted, $Page outputs "4" instead of "2"

Does any one know why this is?

Thnx!

d11wtq | Sorted out the

Code: Select all

 tags... NOTE: You only need one set of [php ][/ php] tags around your code.... <?php ?> inside you code is automatically highlighted ;)[/color]
Post Reply