drlma06060 2015-10-11 07:13
浏览 34
已采纳

如何在循环计数++计数器时删除

hello i want to ask on display on my receipt. this is my receipt

|Food Name    |Price|
 Burger No : 1  
|Bun          |$1.00|
|Lamb         |$2.00|
|Pickel       |$1.20|
|Chilli       |$0.60|
 Burger No : 2
|Standard     |$0.80|
|Chicken      |$1.00|
|Normal       |$1.00|
|Normal       |$1.00|
 Burger No : 3
|Crispy       |$1.30|
|Beef         |$1.20|
|Extra        |$1.10|
|Hot          |$1.10|
 Burger No : 4

this is my coding

if($query_run = mysql_query($query1))
            {


                echo "

                <tr>
                <td>Food Name</td>
                <td>Price</td>
                </tr>";

                $counter = 0;

                while($row = mysql_fetch_array($query_run))
                {

                    if($counter==0)
                     {
                     echo"<tr>
                        <td>Burger No:1</td>
                        </tr>";
                     }

                    echo "<tr>
                    <td>".$row['fname']."</td>
                    <td>$".$row['total']."</td>
                    </tr>";

                    $total_price += $row['total'];
                    //echo "burger $counter";
                     $counter++;

                     if($counter==4)
                     {
                     echo"<tr>
                        <td>Burger No:2</td>
                        </tr>";
                     }

                     if($counter==8)
                     {
                     echo"<tr>
                        <td>Burger No:3</td>
                        </tr>";
                     }

                     if($counter==12)
                     {
                     echo"<tr>
                        <td>Burger No:4</td>
                        </tr>";
                     }


                }

my question is how can i remove the burger no example below:

if i buy 8 items then it should display burger no 1 and burger no 2 list...but the burger no 3 will also appear, same goes if i buy 12 items the burger no 4 will appear. How can i remove the burger no?

Please and thank you for your cooperation.

  • 写回答

1条回答 默认 最新

  • dongzhou1865 2015-10-11 07:25
    关注

    Add condition like

    $num_rows = mysql_num_rows($query_run);
    while($row = mysql_fetch_array($query_run))
    {
    
      if($counter==0){
         echo"<tr>
           <td>Burger No:1</td>
          </tr>";
      }
    
                    echo "<tr>
                    <td>".$row['fname']."</td>
                    <td>$".$row['total']."</td>
                    </tr>";
    
                    $total_price += $row['total'];
                    //echo "burger $counter";
                     $counter++;
    
                   if($counter < $num_rows) {
                     if($counter==4 )
                     {
                     echo"<tr>
                        <td>Burger No:2</td>
                        </tr>";
                     }
    
                     if($counter==8)
                     {
                     echo"<tr>
                        <td>Burger No:3</td>
                        </tr>";
                     }
    
                     if($counter==12)
                     {
                     echo"<tr>
                        <td>Burger No:4</td>
                        </tr>";
                     }
                  }
    
    
                }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算