2

我有一个硬件问题,要求我计算超过 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>
4

1 回答 1

1
  • 开始创建一个编号为 0 的变量。比如 $nrsoups = 0;

  • 当某一天的价格大于 2 时,将该值(变量 $nrsoups)增加 1

  • Nr 汤超过 2 美元 = $nrsoups

就像是:

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

ETC...

于 2013-04-22T22:20:16.887 回答