...

View Full Version : +1? How!?!



the-dream
03-29-2007, 07:27 PM
hi how do i plus 1 to a var eg


<?php
$curpg = $_GET['curpage'];
$nxtpg = ''; // here is where i am stuck i want to do curpage +1 but i don't know how

I have searched this in Google and it comes up with things like ' Adding PHP To A Webpage! '

Please Help!

rafiki
03-29-2007, 07:32 PM
$curpg = $_GET['curpage'];
$nxtpg = "$curpg++";
this work?

the-dream
03-29-2007, 07:38 PM
that just adds ++ to the end of my URL parameter
Look:
index.php?curpage=1++

Nimlhg
03-29-2007, 07:38 PM
Is this question some kind of joke?



$curpg = $_GET['curpage'];
$nxtpg = "$curpg++";
this work?


There's no need for those double quotes.

This works:


$curpg = intval( $_GET['curpage'] );
$nxtpg = $curpg + 1;

the-dream
03-29-2007, 08:05 PM
cheers

Spookster
03-29-2007, 08:12 PM
To increment a number variable rafiki was correct you just need to use the ++ operator. Just lose the quotes around it otherwise it will treated as a string which is why you got the characters ++ at the end.

$curpg = curpg + 1 is the same as $curpg++.

the-dream
03-29-2007, 08:14 PM
ok sos!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum