如何删除循环中的行或任何其他方法以显示如下所示

时间:2012-12-13 15:37:34

标签: php mysql

需要的显示 enter image description here

这里是我的代码和显示

<table width="100%" cellspacing="0" cellpadding="0" summary="" id="box-table-a">
        <thead>
          <tr>
            <th width="" scope="col"><strong>Item Description</strong></th>
            <th scope="col" style="text-align:center;"><strong>Quantity</strong></th>
            <th width="350" scope="col"><strong>Supplier Name</strong></th>
            <th scope="col" style="text-align:center;"><strong>Unit Price Rs.</strong></th>
            <th scope="col" style="text-align:center;"><strong>VAT Price Rs.</strong></th>
            <th width="100" scope="col"><strong>Total Price Rs.</strong></th>
          </tr>
        </thead>
        <tbody>

          <?php 


          $get_data =mysql_query("SELECT supplier_add_quotaion_form.quotaion_request_id,supplier_add_quotaion_form.supplier_id,supplier_add_quotaion_form.supplier_add_quotaion_id,supplier_add_quotaion_request_item.* FROM supplier_add_quotaion_request_item,supplier_add_quotaion_form 
WHERE supplier_add_quotaion_form.supplier_add_quotaion_id=supplier_add_quotaion_request_item.supplier_add_quotaion_id AND supplier_add_quotaion_form.quotaion_request_id='$id' ORDER BY quotation_item_id");


            while($row = mysql_fetch_array($get_data)){ 
                $quotaion_request_id = $row['quotaion_request_id'];
                $supplier_add_quotaion_id = $row['supplier_add_quotaion_id'];
                $supplier_id = $row['supplier_id'];
                $net_item_value = $row['net_item_value'];
                $vat_item_value = $row['vat_item_value'];
                $total_value = $row['total_value'];
                $quotation_item_id = $row['quotation_item_id'];


                 $get_count = mysql_query("SELECT quotation_item_id FROM supplier_add_quotaion_request_item WHERE quotation_item_id='$quotation_item_id'"); 

                $count = mysql_num_rows($get_count);


                $get_quantity = mysql_query("SELECT quantity_required,item_description FROM clerk_add_quotaion_request_item WHERE quotation_item_id='$quotation_item_id'"); 

                    while($rowB = mysql_fetch_array($get_quantity)){ 
                        $quantity_required = $rowB['quantity_required'];
                        $item_description = $rowB['item_description'];
                    }



            ?>

          <tr>
            <td><?php echo $item_description; ?></td>
            <td align="center"><?php echo $quantity_required; ?></td>
            <td><?php echo $supplier_id; ?></td>
            <td align="center"><?php echo $net_item_value; ?></td>
            <td align="center"><?php echo $vat_item_value; ?></td>
            <td align="center"><?php echo $total_value; ?></td>
          </tr>

          <?php
            }
        ?>
        </tbody>

enter image description here

  • 当重复描述需要rowpan他们或者什么方法需要显示为第一个图像..我尝试它得到计数,然后根据它的rowspan.but无法显示,不知道如何删除额外细胞
  • 重复行计数未修复,仅示例显示第一张图片,一个描述可以是1-7范围重复(对于一个项目,7个供应商可以出价)

supplier_add_quotaion_form表格结构

supplier_add_quotaion_request_item

supplier_add_quotaion_request_item表格结构

supplier_add_quotaion_form table structure

clerk_add_quotaion_request_item结构

enter image description here

3 个答案:

答案 0 :(得分:0)

将查询结果简化为结构化数组可能会更容易,然后您可以轻松地从中检索必要的计数以执行您的行扫描:

$data = array();
while ($row = mysql_fetch_assoc($result)) {
   $data[$row['item_description']][] = $row;
}

echo "start your table here";
foreach($data as $description => $items) {
    echo "<tr><td rowspan=" . count($items) . ">";
    foreach($items as $item) {
        output item data here
    }
}

这不会按原样运作,但应该让你知道如何去做。

答案 1 :(得分:0)

你可以一次完成这个,试试这个

<?php 
          $get_data =mysql_query("...");

          $last_quotaion_request_id = -1;
            while($row = mysql_fetch_array($get_data)){ 
                $quotaion_request_id = $row['quotaion_request_id'];
                $supplier_add_quotaion_id = $row['supplier_add_quotaion_id'];
                $supplier_id = $row['supplier_id'];
                $net_item_value = $row['net_item_value'];
                $vat_item_value = $row['vat_item_value'];
                $total_value = $row['total_value'];
                $quotation_item_id = $row['quotation_item_id'];


                 $get_count = mysql_query("SELECT quotation_item_id FROM supplier_add_quotaion_request_item WHERE quotation_item_id='$quotation_item_id'"); 

                $count = mysql_num_rows($get_count);


                $get_quantity = mysql_query("SELECT quantity_required,item_description FROM clerk_add_quotaion_request_item WHERE quotation_item_id='$quotation_item_id'"); 

                    while($rowB = mysql_fetch_array($get_quantity)){ 
                        $quantity_required = $rowB['quantity_required'];
                        $item_description = $rowB['item_description'];
                    }



            ?>

          <tr>
            <?php if($last_quotaion_request_id != $quotaion_request_id){ ?>
            <td rowspan="<?php echo $count; ?>"><?php echo $item_description; ?></td>
            <td rowspan="<?php echo $count; ?>" align="center"><?php echo $quantity_required; ?></td>
            <?php } ?>
            <td><?php echo $supplier_id; ?></td>
            <td align="center"><?php echo $net_item_value; ?></td>
            <td align="center"><?php echo $vat_item_value; ?></td>
            <td align="center"><?php echo $total_value; ?></td>
          </tr>

          <?php
            $last_quotaion_request_id = $quotaion_request_id;
            }
        ?>

答案 2 :(得分:0)

您需要更改正在使用的表的结构。根据我的猜测,我提出了一个建议。将项目描述保留在表格中,将报价详细信息保存在另一个表格中。在获取数据时,您可以使用group by sql命令获取数据。

你的项目表可能是这样的:

 1. id
 2. desc
 3. clicks

和引用表可能是这样的

 1. id
 2. item_id
 3. supplier
 4. quantity
 5. vat
 6. price

等。