第31例
用户输入日期查询备忘录
<?php
header("Content-Type:text/html;charset=utf-8");
?>
<form action="index.php" method="post">
<b>输入日期:</b><br />
<input type="text" name="date"/><br />
<input type="submit" value="查询"/>
<input type="reset"/>
</form>
<?php
if(!empty($_POST['date']))
{
$date=$_POST['date'];
$rc=array(); //数组
$rc['5-1']='查看网站 IT1994.cn';
$rc['5-2']='同学聚会';
$rc['5-3']='购物';
$rc['5-4']='出差';
$rc['5-5']='发邮件';
foreach($rc as $key=>$value)
{
if($key==$date)
{
echo "<script>alert('".$key."日备忘录:".$value."')</script>";
}else
{
echo "<script>alert('无备忘录')</script>";
break;
}
}
}
?>
第32例
隔行换色
<?php
header("Content-Type:text/html;charset=utf-8");
echo "<center><b>隔行换色</b></center>";
$color="";
echo '<table border="1" width="200" height="200" align="center" cellspacing="0">';
for($i=0;$i<5;$i++)
{
if($i%2==0)
{
$color="red";
}else
{
$color="blue";
}
echo "<tr bgcolor='".$color."'>";//输出行并把颜色赋值给背景
for($j=0;$j<5;$j++)
{
echo "<td>".$j."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
第33例
输出倒序乘法表
<?php
header("Content-type:text/html;charset=utf-8");
for($i=9;$i>=1;$i--)
{
for($j=$i;$j>=1;$j--)
{
echo "$i*$j=".($i*$j)." ";
}
echo "<br/>";
}
?>
第34例
表格计算器
<?php
header("Content-Type:text/html;charset=utf-8");
?>
<form action="index.php" method="post">
结果:<input type="text" name="sum" id="sum" size="15"/><br />
数字1:<input type="text" name="num1" size="10"/><br />
运算符:<select name="sub">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br />
数字2<input type="text" name="num2" id="num2" size="10"/><br />
<input type="submit" value="计算"/>
<input type="reset"/>
</form>
<?php
if(!empty($_POST['num1']))
{
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$sub=$_POST['sub'];
$sum=0;
switch($sub)
{
case "+":
$sum=$num1+$num2;
break;
case "-":
$sum=$num1-$num2;
break;
case "*":
$sum=$num1*$num2;
break;
case "/":
$sum=$num1/$num2;
break;
}
echo "<script>alert('计算出结果为:".$sum."');</script>";
echo "<script>document.getElementById('sum').value='".$sum."'</script>";
}
?>
第35例
php动态表格生成器
<style type="text/css">
body{
background:#ccc;
}
</style>
<form action="35.php" method="post">
<b>输入行列生成表格</b><br><br>
输入行:<input type="text" name="cols"><br><br>
输入列:<input type="text" name="rows"><br><br>
<input type="submit" value="生成表格">
<input type="reset" value="重置行列">
</form>
<?php
header("Content-Type:text/html;charset=utf-8");
if(!empty($_POST['cols'])){
echo"<center><b>用户动态输出表格.行".$_POST['cols'].",列".$_POST['rows']."</b></center>";
$color="";
echo "<table border='1' width='200px' height='200px' align='center' cellspacing='0'>";
for($i = 0 ; $i < $_POST['cols'] ; $i++){
if($i%2==0){
$color="red";
}else{
$color="blue";
}
echo "<tr bgcolor='".$color."'>";
for($j = 0 ;$j < $_POST['rows'] ; $j++){
echo "<td>".$j."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
转载于:https://blog.51cto.com/8281493/1623811