如何使用增量计算超过特定价格的东西

时间:2013-04-22 21:52:09

标签: php html conditional

我有一个问题,如果有人进入,我会要求我计算超过2美元的汤数。我的教授暗示我应该使用递增来计算超过2美元的汤数。我的PHP代码如下。我是PHP的新手,我的教授在提供示例,指导和成为一名教师方面非常匮乏。任何帮助都会很棒!

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
 <title>Cafe</title>
<style type="text/css" media="screen"> .error { color: red; } </style>
</head>

 <body>

 <?php
$monday = $_POST['monday'];
$tuesday = $_POST['tuesday'];
$wednesday = $_POST['wednesday'];
$thursday = $_POST['thursday'];
$friday = $_POST['friday'];
$monday_item = $_POST['monday_item'];
$tuesday_item = $_POST['tuesday_item'];
$wednesday_item = $_POST['wednesday_item'];
$thursday_item = $_POST['thursday_item'];
$friday_item = $_POST['friday_item'];
$m_price = $_POST['m_price'];
$t_price = $_POST['t_price'];
$w_price = $_POST['w_price'];
$th_price = $_POST['th_price'];
$f_price = $_POST['f_price'];
$total = ($m_price + $t_price + $w_price + $th_price + $f_price);


if( empty ($_POST['tuesday']))
{print '<p class="error"> You did not complete all of the required fields</p>';
$okay = FALSE;
}

if ( !is_numeric ($_POST['th_price']))
{print '<p class="error"> That is not a number </p>';
$okay = FALSE;
}

if ($_POST['m_price'] > 10)
{print '<p class="error"> That is too Much!!! </p>';
}

if($total > 10):
echo "total is greater than 10";
elseif($total == $b): // Note the combination of the words.
echo "total equals 10";
else:
echo "total is less than 10";
endif;

if ($_POST['m_price'] > 2)
{print }



print
"<table border='1'>";
print "<tr>
                    <td> $monday </td>
                    <td> $monday_item </td>
                    <td> $m_price </td>
            </tr>
            <tr>
                        <td> $tuesday </td>
                        <td> $tuesday_item </td>
                        <td> $t_price </td>
            </tr>
            <tr>
                        <td> $wednesday </td>
                        <td> $wednesday_item </td>
                        <td> $w_price </td>
            </tr>
            <tr>
                        <td> $thursday </td>
                        <td> $thursday_item</td>
                        <td> $th_price </td>
            </tr>
            <tr>
                        <td> $friday </td>
                        <td> $friday_item </td>
                        <td> $f_price </td>
            </tr>";
        print   "</table>";

    print "<p> Your total price of soups is $total </p>";

    ?>


  </body>
   </html>

1 个答案:

答案 0 :(得分:1)

  • 开始创建一个数字为0的变量,例如$ nrsoups = 0;

  • 当价格较大时,将该值(变量$ nrsoups)增加一个 那么两天某一天

  • 超过2美元的汤数= $ nrsoups

类似的东西:

$nrsoups = 0;
if ($_POST['m_price'] > 2) $nrsoups++;
if ($_POST['t_price'] > 2) $nrsoups++;

等...