1

I need to pass the value of page by increasing one. This is my pure code

<?php echo "<li><a href='pro.php?page=$page'><span class='ico-next'></span></a></li>" ?>

this is I tried one

<?php echo "<li><a href='pro.php?page=.$page++.'><span class='ico-next'></span></a></li>" ?>

But its not working,how can I pass the value by increasing it by one

4
  • $page = $page++; or ++$page Jun 8, 2017 at 13:28
  • Where do you read your GET/POST variable? $_GET Jun 8, 2017 at 13:30
  • <a href='pro.php?page=".(++$page).">
    – Kazz
    Jun 8, 2017 at 13:31
  • your second attempt is almost correct, you simply need to end the string so you concatenate onto it, rather than within it, ?page=".$page++."'> (note the quotes added to close/open the string)
    – Martin
    Jun 8, 2017 at 13:34

2 Answers 2

1

This is not possible due to limitations of the php parser. You have to use concatenation instead:

<?php echo "<li><a href='pro.php?page=" . ++$page . "'>";

Some find it easier to read such style, it separates formatting and computation:

<?php echo sprintf("<li><a href='pro.php?page=%s'>", ++$page);

Note that you probably also need to use ++$page instead of $page++, though that depends on your actual situation.

1
  • Thank u very much :)
    – Rooter
    Jun 8, 2017 at 16:07
1

You first need to increment the variable before you print it to the page.

<?php echo "<li><a href='pro.php?page=".trim(++$page)."'><span class='ico-next'></span></a></li>" ?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.