How to accept number from User and print table using php for loop?

9

<html>
<head>
<title>Code to print table</title>
</head>
<body>
<form action=“” method=“post”>
Enter the Number<input type=“text” name=“num” value=“” />
<br />
<input type=“submit” name=“btn” value=“submit” />
<?php
if(isset($_POST[‘btn’]))
{
$num1=$_POST[‘num’];
for($i=1;$i<=10;$i++)
{
$t=$num1*$i;
echo “<br>”.$t;
}
}
?>
</form>
</body>
</html>

<html>

<head>

<title>for loop example</title>

</head>

 

<body>

<form name=”frm” action=”” method=”post”>

Enter your name

<input type=”text” name=”name” />

Enter How many times do you print your name ????????

<input type=”text” name=”num” /><br />

<input type=”submit” name=”btn” value=”print my name” />

</form>

<?php

if(isset($_POST[‘btn’]))

{

$name=$_POST[‘name’];

$num=$_POST[‘num’];

for($i=1;$i<=$num;$i++)

{if($i%2==0){

echo “<font color=’red’>”.$name.”</font>”.”<br>”;}

else{

echo “<font color=’green’>”.$name.”</font>”.”<br>”;}

}

}

?>

</body>

</html>

Please follow and like us:
0

Add a Comment

Your email address will not be published. Required fields are marked *