我想在循环之后添加一行,根据用户的订单,LAST行之前的行数是随机的。所以例如用户订购10,我想在列表中添加另一行。即使订单为3,最后仍会有另一行。
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$row['prod_name']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "<td>₱".number_format(($row['price']*$row['quantity']),2)."</td>";
echo "</tr>";
if($row['carrier']=="LBC"){
echo "<tr>";
echo "<td>Shippment Option Chosen: ".$row['carrier']."</td>";
echo "<td></td>";
echo "<td>₱250.00</td>";
echo "</tr>";
}
}
echo "</table>";
?>
在这里,我创建了另一行,但它在每行之后创建了一行,我只需要在表的末尾添加1行。谢谢:))
答案 0 :(得分:0)
您应该在
之前添加一行echo "</table>";
行,但在它之前的结束括号之后。最后一个结束括号是你的循环结束的地方。它应该是这样的:
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$row['prod_name']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "<td>₱".number_format(($row['price']*$row['quantity']),2)."</td>";
echo "</tr>";
if($row['carrier']=="LBC"){
echo "<tr>";
echo "<td>Shippment Option Chosen: ".$row['carrier']."</td>";
echo "<td></td>";
echo "<td>₱250.00</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td>LAST LINE...</td>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
?>
答案 1 :(得分:0)
您可以使用mysqli_num_rows获取否。的行。然后你可以在while循环中添加一个计数器。当counter = mysqli_num_rows时,你可以回显你想要回显的行
示例:
$totalrows=mysqli_num_rows($result);
$counter=1;
while ($row=mysql_fetch_array($result)){
//echo the row data
if($counter==$totalrows)
{
//echo the extra row which you wanted.
}
}
echo "</table>";
答案 2 :(得分:0)
嗯为什么不添加新查询?我修改了你的代码。并添加了这些。
$qryx = "SELECT DISTINCT customers.serial,customers.name,customers.payment,customers.carrier,customers.tracking_no, orders.date, order_detail.productid, order_detail.quantity, order_detail.price, order_detail.orderid, inventory.prod_name
FROM customers
RIGHT JOIN orders on customers.serial=orders.serial
RIGHT JOIN order_detail on orders.serial=order_detail.orderid
LEFT JOIN inventory on order_detail.productid=inventory.prod_id
where customers.email='{$_SESSION['email']}'
AND order_detail.orderid='{$_REQUEST['orderid']}'
GROUP BY customers.carrier";
$resulty = @mysql_query($qryx);
while ($rowz=mysql_fetch_array($resulty)){
if($rowz['carrier']=="LBC"){
echo "<tr>";
echo "<td>Shippment Option Chosen: ".$rowz['carrier']."</td>";
echo "<td></td>";
echo "<td>₱250.00</td>";
echo "</tr>";
}
}
我更改了qry,result和row的名称。并添加了DISTINCT和GROUP BY来删除冗余。