FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » initial value
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: initial value [message #171171 is a reply to message #171158] Tue, 28 December 2010 20:41 Go to previous message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma:
Member
Helmut Chang wrote:
> Am 28.12.2010 17:30, schrieb richard:
>> $year=$_GET(yearID)
>> echo $year
>>
>> Works just fine except for one thing.
>
> Don't think so.
>
> 1. $_GET is an array and elements in an array are accessed by square
> brackets:
>
> $_GET[] not $_GET()
>
> 2. As long, as yearID is not defined as constants, but you mean the
> string 'yearID', you should use '':
>
> $_GET['yearID'] instead of $_GET[yearID]
>
>> When the page is initially loaded, there is nothing in the space.
>> I want to show a year in the space as the default.
>> So that $year should have a value other than null.
>> How is that done?
>
> In initializing the variable with a default value:
>
> $year = 2010;

Just a minor addition. Make it perpetual and change that to:

$year = date('Y);

And note: The word "initial" in the subject is they key here. Even
though Php does not require it, it is always best to initialize
("define") your variables before using them, usually near the top of the
script where it easy to see what variables are used (documentation).

>
> if (isset($_GET['yearID']))
> $year = $_GET['yearID'];
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Problem Connecting to PHP
Next Topic: Open Session Variables
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 20:37:39 GMT 2024

Total time taken to generate the page: 0.09202 seconds