如何使用增量来计算某物超过一定的价格


How to use increment to count something over a certain price

我有一个问题,要求我计算如果有人要输入超过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>
  • 开始创建编号为0的变量。

  • 当价格较大时,将该值(变量$nrsoup)增加1然后一天两个

  • 超过2美元的汤的数量= $nrsoup

类似:

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

等等…