Re: basic php problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15/06/06, Ross <ross@xxxxxxxxxxxxx> wrote:


I want to set a page number of a page

if(!isset($_REQUEST['page'])) {
$page =$_REQUEST['page'] + 1;
echo "page is ".$page; // this echos out page is 1


}


The problem is when I try and use $page further down in the body $page is
0

Question <?=$page; ?> <BR />
<? echo "page is".$page; ?>
<?=$question[($page-1)]; ?>


I also get an undefined index notice

Notice: Undefined index: page in
c:\Inetpub\wwwroot\lss\module_one\evaluation.php on line 8
page is 1

but I though if I do a if(!isset($_REQUEST['page'])) this is the way to
set
a previously undefined index?

Ross


Firstly, there is no need to set the page by adding 1 to $_REQUEST['page']
if $_REQUEST['page'] is not set, why not do this:

$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;

(ternary operator)






--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux