Sunday, May 31, 2009

Multiplication Table via PHP SCRIPT - FOR Loop


Get Your Multiplication Table



No. of Columns

No. of Rows






PHP SCRIPT


<?php
echo "<h1>Multiplication table</h1>";
echo "<table border=1 bgcolor=#d0e2ff width=25%";

for ($col = 1; $col <= $_POST[columns]; $col++ ) { //this is the outer loop
echo "<tr>";
echo "<td><font color =blue><b>".$col."</b></font></td>";

for ( $row = 2; $row <= $_POST[rows]; $row++ ) { // inner loop
echo "<td>".$col * $row."</td>";
}

echo "</tr>";
}

echo "</table>";
?>

SWITCH Conditional

This is a sample SWITCH conditional for the same function as that of the IF-ELSE script.

<?php

switch ($_POST[number]) {
case 0:
echo "The number you entered is <b>Zero</b>";
break;
case ($_POST >0):
echo "The number you entered is a <b>Positive</b> integer!";
break;
case ($_POST <0):
echo "The number you entered is a <b>Negative</b> integer!";
break;

}

?>

PHP Conditional Script

This is a sample of a conditional PHP script where in the script identifies a number if it is zero, positive, negative or not a number at all.

Any number entered in the html form below will be identified.


Enter a Number



The PHP script uses the conditional statements IF, ELSE & ELSEIF to display if the number entered is zero or positive or negative or not a number at all.

<?php

IF ($_POST[number]=="0") echo "The number you entered is <b>Zero</b>";
elseif ($_POST[number] > 0)
echo "The number you entered is a <b>Positive</b> integer!";
elseif ($_POST[number] < 0)
echo "The number you entered is a <b>Negative</b> integer!";
ELSE echo "You did not enter a valid number!";

?>

  © Blogger template 'Minimalist G' by Ourblogtemplates.com 2008

Back to TOP