Page 1 of 1

new to php

Posted: Wed Jan 05, 2005 3:13 pm
by rodrigorules
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. :P

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?

Posted: Wed Jan 05, 2005 3:36 pm
by andre_c
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'

Posted: Wed Jan 05, 2005 3:38 pm
by alix
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

Posted: Wed Jan 05, 2005 3:48 pm
by rodrigorules
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...?

Posted: Wed Jan 05, 2005 3:53 pm
by feyd
gentlemen, remember to read the posting code guidelines. :?

Posted: Wed Jan 05, 2005 3:57 pm
by rodrigorules
hmm ya sry i read it now ...ill edit my post
so why the <br /> ?

Posted: Wed Jan 05, 2005 4:12 pm
by rodrigorules
another question...
why do i get parse error...omg
nothing wrong

Code: Select all

<?php

for ($p=5; $i=100; $i<=0; $i--$p;)
&#123;
echo "$i <br>";
&#125;
?>

Posted: Wed Jan 05, 2005 4:29 pm
by feyd
  1. too many parameters for a for loop
  2. invalid syntax for your math in the increment (last) expression of your for loop set up.
  3. 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 />";
}

Posted: Wed Jan 05, 2005 4:57 pm
by kzar
i also wondered about the <br /> stuff

Posted: Wed Jan 05, 2005 4:58 pm
by v3xtra
IT's XML, all tags must have a closing tag, even image tags and break tags. It works the same.

Posted: Wed Jan 05, 2005 5:08 pm
by rodrigorules
feyd wrote:
  1. too many parameters for a for loop
  2. invalid syntax for your math in the increment (last) expression of your for loop set up.
  3. 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

Posted: Wed Jan 05, 2005 5:20 pm
by feyd
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.

Posted: Wed Jan 05, 2005 5:37 pm
by rodrigorules
lol didnt notice!
thanks for fixing it :D