new to php

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

Post Reply
rodrigorules
Forum Commoner
Posts: 35
Joined: Wed Jan 05, 2005 3:10 pm

new to php

Post 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?
Last edited by rodrigorules on Wed Jan 05, 2005 3:58 pm, edited 1 time in total.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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'
alix
Forum Commoner
Posts: 42
Joined: Thu Nov 18, 2004 8:41 am

Post 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
rodrigorules
Forum Commoner
Posts: 35
Joined: Wed Jan 05, 2005 3:10 pm

Post 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...?
Last edited by rodrigorules on Wed Jan 05, 2005 3:58 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

gentlemen, remember to read the posting code guidelines. :?
rodrigorules
Forum Commoner
Posts: 35
Joined: Wed Jan 05, 2005 3:10 pm

Post by rodrigorules »

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 »

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;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 />";
}
kzar
Forum Newbie
Posts: 16
Joined: Thu Nov 25, 2004 3:03 pm

Post by kzar »

i also wondered about the <br /> stuff
v3xtra
Forum Newbie
Posts: 14
Joined: Wed Jan 05, 2005 4:56 pm

Post by v3xtra »

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 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
rodrigorules
Forum Commoner
Posts: 35
Joined: Wed Jan 05, 2005 3:10 pm

Post by rodrigorules »

lol didnt notice!
thanks for fixing it :D
Post Reply