自学PHP的笔记(七)小例子两头

来源:互联网 发布:js视频 编辑:程序博客网 时间:2024/05/08 17:11

第一个
 <html>
<head>
 <title>Lee's Auto Parts - Order Results</title>
</head>
<body>
 <h1>Bob's Auto Parts</h1>
 <h2>Order Results</h2>
 <?php
  //定义变量
  $totalqty = 0;
  $totalamount = 0.00;
  $tireqty = $_POST['tireqty'];
  $oilqty = $_POST['oilqty'];
  $sparkqty = $_POST['spqty'];
  $find = $_POST['find'];
  $taxrate=0.00;
  //定义常量
  define('TLREPRICE',100);
  define('OILPRICE',10);
  define('SPAKPRICE',4);
  
  //计算订单购买件数
  $totalqty = $tireqty + $oilqty + $sparkqty;
  echo '<p>Your order is as follows;</p>';
  if($totalqty == 0){
   echo 'You did not order anything on the previous page! <br/>';
  }else{
   if($tireqty > 0){
    echo $tireqty.'tires<br />';
    }
   if($oilqty > 0){
    echo $oilqty.'bottles of oil<br />';
    }
   if($sparkqty > 0){
    echo $sparkqty.'spark plugs<br />';
    }
  switch($find){
   case "a":
    echo 'Regular customer.<br/>';
    break;
   case "b":
    echo 'Customer referred by TV advert.<br/>';
    break;
   case "c":
    echo 'Customer referred by phone directory<br/>';
    break;
   case "d":
    echo 'Customer referred by word of mouth.v';
    break;
   default :
    echo 'We do not know how this customer found us.<br/>';
    break; 
  }  
   //计算总价
   $totalamount = $tireqty * TLREPRICE
      + $oilqty * OILPRICE
      + $sparkqty * SPAKPRICE;
   echo "Items orderd: ".$totalqty."<br/>";
   echo "Subtotal: $".number_format($totalamount,2)."<br />"; 
   if($totalqty < 10 ){
    $taxrate=0.00;
   }elseif($totalqty >= 10 && $totalqty <= 49)
   {
    $taxrate=0.05;
   }elseif($totalqty >= 50 && $totalqty <= 99)
   {
    $taxrate=0.10;
   }elseif($totalqty >= 100)
   {
    $taxrate=0.15;
   }
   echo "Discount:".$taxrate." Taxrate:0.1<br/>";
   //计算税后总价
   $totalamount=$totalamount*1.1*(1-$taxrate); 
   echo "Total including tax:$".number_format($totalamount,2)."<br/>";
  } 
 ?>
 
</body>
</html>

 

 

 

 

<form action="ProcessOrder.php" method="post">
   <table border ="0">
  <tr bgcolor="#cccccc">
   <td width="150">Item</td>
   <td>Quantity</td>
  <tr/>
  <tr>
   <td>Tires</td>
   <td align="center"><input type="text" name="tireqty" size="3" maxlength="3"/></td>
  <tr/>
  <tr>
   <td>Oil</td>
   <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"/></td>
  <tr/>
  <tr>
   <td>Spark Plugs</td>
   <td align="center"><input type="text" name="spqty" size="3" maxlength="3"/></td>
  <tr/>
  <tr>
   <td>How did you find Bob?</td>
   <td><select name = "find">
     <option value = "a">I'm a regular customer</option>
     <option value = "b">TV advertising</option>
     <option value = "c">Phone directory</option>
     <option value = "d">Word of mouth</option>
    </select>
   </td>
  </td>
  <tr>
   <td align="center"><input type="submit" value="Submit Order"/></td>
  <tr/>
   </table>
</form>

 

 

第二个

<?php
 $pictures= array('1.bmp','2.bmp','3.bmp','4.bmp','5.bmp','6.bmp','7.bmp','8.bmp','9.bmp','10.bmp');
 shuffle($pictures);
?>
<html>
<head>
<title>Bob's Auto Parts</title>
</head>
<body>
 <h1>Bob's Auto Parts</h1>
 <div align="center">
  <table>
   <tr>
    <?php
     for($i=0;$i<3;$i++){
      echo "<td align=\"center\"><img src=\"image/";
      echo $pictures[$i];
      echo "\"width=\"399\"/></td>";
     }
    ?>
   </tr>
  </table>
 </div>
</body>
</html>

原创粉丝点击