Aims:
$num_of_students = (int) $_GET['num_of_students']; $num_of_staff = (int) $_GET['num_of_staff']; $num_of_students_per_staff = $num_of_students / $num_of_staff; echo '<p>'; echo $num_of_students_per_staff; echo '</p>';
$num_of_students = $_GET['num_of_students']; $num_of_staff = $_GET['num_of_staff']; $num_of_students_per_staff = $num_of_students / $num_of_staff; echo '<p>'; echo $num_of_students_per_staff; echo '</p>';Asking PHP to divide one string by another doesn't make sense!
$num_of_students = (int) $_GET['num_of_students']; $num_of_staff = (int) $_GET['num_of_staff']; $num_of_students_per_staff = $num_of_students / $num_of_staff; echo '<p>The staff-student ratio in your college is: ' . $num_of_students_per_staff . '</p>';
$num_of_students = (int) $_GET['num_of_students']; $num_of_staff = (int) $_GET['num_of_staff']; $num_of_students_per_staff = $num_of_students / $num_of_staff; echo "<p>The staff-student ratio in your college is: {$num_of_students_per_staff}</p>";
age_form.html
contains this form:
<form action="next_age.php" method="get"> <input type="text" name="firstname" /> <input type="text" name="age" value="0" /> <input type="submit" /> </form>
next_age.php
which tells the user his/her age next birthday
Derek, on your next birthday you will be 29
from | to | |
---|---|---|
float | int | truncate the decimal places e.g. 7.6 becomes 7 |
int | float | nothing much to be done e.g. 12 becomes 12.0 |
int/float | string | nothing much to be done e.g. 12 becomes '12'; 7.6 becomes '7.6' |
string | int/float | the start of the string is interpreted as
a number, if it can be otherwise, the string is converted to 0 e.g. '7' becomes 7; '12.2blah' becomes 12.2; '0.5E2 ' becomes 0.5E2 (i.e. 50.0); 'Hello' becomes 0; ' 7' becomes 7 |
(Lots of little details suppressed here, e.g. what if you try to convert something that's too big)
<form action="curry_powder_order.php" method="get"> <input type="text" name="num_of_small_bags" value="0" /> <input type="text" name="num_of_large_bags" value="0" /> <input type="submit" /> </form>
curry_powder_order.php
which outputs an unordered list,
like the following for a user who ordered 3 of the smaller bags and 2 of the larger
bags:
- 3 * small bags: 75kg
- 2 * large bags: 100kg
- Total weight: 175kg