Re: I am really new to Php, I wonde if somebody can show me,
Posted: Fri Feb 03, 2012 1:46 pm
Thank you so much again, I will try. I really really appreciate your help!!!!!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
A. & D. Wherever you want a space, you must put space in your quoted string. You can combine all of the output into one echo command, in fact a good way to do it is to build the string first, using the . PHP operator, which is the concatenation operator (means put together), then just echo the string, like this:djkazoo2002 wrote:Once again, I am having a problem. the professor changed his mind, and he wants us to diplay -------- $Studentnumber gets $Grade because his/her score is $his/her score.---------
for exapmle, 123 gets A because her/his score is 95
A, I want to make a space, like sentence, "his score is78," I want "his score is 78"
B, Grade did not show up. how can I write correctly on php.
C,This F " F123's" kept showing up
D, I want to one sentence echo not like,
echo $_POST["studentnumber"] ;
echo "'s grade is <br/>";
echo $grade = isset($_POST['grade']) ? $_POST['grade'] : 0;
echo "because his score is";
echo $_POST["grade"];
Code: Select all
$str = $_POST['studentnumber'] . "'s grade is " . $grade " . " because his score is " . $_POST['grade'];
echo $str;djkazoo2002 wrote:Prompt user for his or her birth date.
Calculate the user’s age.
Display the user’s birth date and age
so I did like this, after I googled it how to do that, It seems like that there are so many ways, but after I tested it around, I think this is the most easiest way,
Here you need to test whether you want to display the form or calculate and display the results.
You could do this by testing whether there is a value for $_POST['BirthMonth'], for example.
Based on that, you can start an if ... else block here -- the first block is for when $_POST[/BirthMonth'] is empty:
<form name="input" action="birthday2.php" method="post">
when is your birthday? <br/>
<select name="BirthMonth">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="BirthDay">
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="BirthYear">
<?php
for ($i=2012; $i>=1900; $i--)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<input type="submit" value="submit" />
Here's where the first block ends and the else begins -- this is for when the user has filled in at least the BirthMonth:
<?php
//he/she types Birthday
$uM = $_POST['BirthMonth'];
$uD = $_POST['BirthDay'];
$uY = $_POST['BirthYear'];
//Today's Date
$tM = date ("m");
$tD = date ("d");
$tY = date ("Y");
echo "His/her birthday is ".$uM.".".$uD.".".$uY.".";
echo "<br>";
echo "today's date is"." ".$tM.".".$tD.".".$tY.".";
echo "<br>";
You have an error in the next line. What you want is if ($tM < $uM II ($tM <= $uM))
if ($tM < $uM || ($tM == $uM && $tM < $uM))
{
echo $tY - $uY - 1;
}
else
echo $tY - $uY;
Here's where the second block ends, so you must end the if block.:
?>
however some people use "Function", like this
http://www.geekpedia.com/code38_Calcula ... g-PHP.html
it seems more complicated for me, Here are the questions
A. why do people use "function"? is there any advantages to use "function" on this question?
A function is a way to clarify your code so that it is actually easier to program and MUCH easier for someone to read and understand, as well as be able to use the same function code many times, when that is required (not here). By keeping all the calculations together in the function, then just calling the function in the main part of your code, it makes the code much easier for anyone else or yourself to immediately see what the code is doing.
B. What is this Option Value? like "<option value='$i'>$i</option>";
This is HTML that creates a drop-down Select list lets the user select an option. See http://www.w3schools.com/tags/tag_select.asp. In this case, it will display whatever value is in $i and that's also the value that will be sent to the server in the $_POST array if that Option is selected. These 2 values don't have to be the same, see your month Select element, where it displays the names of the months, but sends the number of the month to the server.
C. what is ||? if ($tM < $uM || ($tM == $uM && $tM < $uM)),
II is the OR operator. Some languages use "OR", but PHP and Javascript use II. && is "AND".
I have a test next week, and I really want to practice more PHP more, so if anybody know website or anything, question like this.