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
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 3:13 pm
hi i host a gameserver, i was planning on making a php site, without the help of others this time
so i wanna learn PHP...
i have a question, (i just started) sry if its a dumb ques.
Code: Select all
<html>
<body><?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?></body>
</html>
the $d=date(D")
the d is the varible, and the date("D") get the date from the computer?
which part of it gets the date?
Last edited by
rodrigorules on Wed Jan 05, 2005 3:58 pm, edited 1 time in total.
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Wed Jan 05, 2005 3:36 pm
date() is a predefined function that grabs the date from the server.
date(); obtains the date and assigns it to $d
so now you can:
echo $d;
which will print the date
date("D") will grab the 3-letter day
if ($d=='Fri') checks to see if $d is equal to 'Fri'
alix
Forum Commoner
Posts: 42 Joined: Thu Nov 18, 2004 8:41 am
Post
by alix » Wed Jan 05, 2005 3:38 pm
Likewise im new, but i think i can answer this..
PHP gets the date from the server, where you place date("D") as the three letter abriviation of the day...
So u were right with what you have.. just an error on ur if statment, should look like this
<html>
<body><?php
$d=date("D");
if ($d=="Fri"){
echo "Have a nice weekend!";
}else{
echo "Have a nice day!";
};
?></body>
</html>
lol, try that
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 3:48 pm
thanks both of you
ANOTHER THING -
i been looking at tutorials and why do they use <BR /> ?
example -
Code: Select all
<?php
echo "The number is " . $i . "<br />";
?>
why use that, when this also works...
Code: Select all
<?php
echo "The number is " . $i . "<br>";
?>
any specail reason?
or does it just work both way...?
Last edited by
rodrigorules on Wed Jan 05, 2005 3:58 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 05, 2005 3:53 pm
gentlemen, remember to read the posting code guidelines.
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 3:57 pm
hmm ya sry i read it now ...ill edit my post
so why the <br /> ?
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 4:12 pm
another question...
why do i get parse error...omg
nothing wrong
Code: Select all
<?php
for ($p=5; $i=100; $i<=0; $i--$p;)
{
echo "$i <br>";
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 05, 2005 4:29 pm
too many parameters for a for loop invalid syntax for your math in the increment (last) expression of your for loop set up. contents of loop will not execute, as the control expression will always be false Code: Select all
for( $p = 5, $i = 100; $i >= 0; $i -= $p)
{
echo "$i <br />";
}
kzar
Forum Newbie
Posts: 16 Joined: Thu Nov 25, 2004 3:03 pm
Post
by kzar » Wed Jan 05, 2005 4:57 pm
i also wondered about the <br /> stuff
v3xtra
Forum Newbie
Posts: 14 Joined: Wed Jan 05, 2005 4:56 pm
Post
by v3xtra » Wed Jan 05, 2005 4:58 pm
IT's XML, all tags must have a closing tag, even image tags and break tags. It works the same.
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 5:08 pm
feyd wrote: too many parameters for a for loop invalid syntax for your math in the increment (last) expression of your for loop set up. contents of loop will not execute, as the control expression will always be false Code: Select all
for( $p = 5, $i = 100; $i >= 0; $i -= $p)
{
echo "$i <br />";
}
how would i make this work?
what i was trying to acomplish was to make it count down from 100 to 0
just a exercise
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 05, 2005 5:20 pm
rodridgorules wrote: how would i make this work?
what i was trying to acomplish was to make it count down from 100 to 0
just a exercise
that's exactly what the code I posted does, which is a fixed version of the code you posted.
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 5:37 pm
lol didnt notice!
thanks for fixing it