Php 回声多回路结构中的堆栈
这是我从数据库中回显内容的php代码Php 回声多回路结构中的堆栈,php,html,css,Php,Html,Css,这是我从数据库中回显内容的php代码 <?php include ("config.php"); $results = $mysqli->query ("SELECT transaction_id FROM orders_list WHERE customer_name = 'Klaudia' ORDER BY id LIMIT 100"); if ($results) { while($obj = $results->fetch_object()
<?php
include ("config.php");
$results = $mysqli->query
("SELECT transaction_id FROM orders_list WHERE customer_name = 'Klaudia' ORDER BY id LIMIT 100");
if ($results) {
while($obj = $results->fetch_object()) {
echo '<div id="thisklop">';
echo '<ul class="ulung">Id_cart';
echo '<li>'.$obj->transaction_id.'</li>';
echo '</ul>';
$thisthat=$obj->transaction_id;
$otherresults = $mysqli->query
("SELECT transaction_id, items, quantity, one_product_price FROM orders_history
WHERE transaction_id = '$thisthat'");
if ($otherresults) {
while($obj = $otherresults->fetch_object()) {
echo '<div>';
echo '<ul class="ulung">Products';
echo '<li>'.$obj->items.'</li>';
echo '</ul>';
echo '</div><br>';
echo '<div>';
echo '<ul class="ulung">Quantity';
echo '<li>'.$obj->quantity.'</li>';
echo '</ul>';
echo '</div><br>';
echo '<div>';
echo '<ul class="ulung">Invoices';
echo '<li>'.$obj->one_product_price.'</li>';
echo '</ul>';
echo '</div><br>';
}
}
echo '</div>';
}
}
?>
从上表中可以看出,id_购物车处于循环中,然后在id_购物车中还有处于循环中的内容
我被困在结构上,我在呼应它。建筑物乱七八糟
首先,在一个查询中更快地获取所有数据,然后首先在数组中收集数据。最后,根据数组构造输出:
<?php
include ("config.php");
$results = $mysqli->query
("
SELECT DISTINCT orders_history.transaction_id,
orders_history.items,
orders_history.quantity,
orders_history.one_product_price
FROM orders_history, orders_list
WHERE orders_history.transaction_id = orders_list.transaction_id
AND orders_list.customer_name = 'Klaudia'"
);
$orders = array();
$html = '';
if ($results) {
while($obj = $results->fetch_object()) {
$orders[$obj->transaction_id][$obj->items] = array('quantity' => $obj->quantity, 'invoices' => $obj->one_product_price);
}
$html .= '<table><tr>';
$html .= '<th>id_cart</th>';
$html .= '<th>products</th>';
$html .= '<th>quantity</th>';
$html .= '<th>invoices</th></tr>';
foreach ($orders AS $order_id => $order) {
$html .= '<tr><td rowspan="' . count($order) . '">' . $order_id . '</td>';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) { $html .= '</tr><tr>'; }
$html .= '<td>' . $item . '</td>';
$html .= '<td>' . $data['quantity'] . '</td>';
$html .= '<td>' . $data['invoices'] . '</td>';
/* INSERTED CODE FOR STATUS */
if ($row == 1) {
$html .= '<tr><td rowspan="' . count($order) . '">' . $status . '</td>';
}
/* END OF INSERTION */
$row++;
}
$html .= '</tr>';
}
$html .= '</table>';
}
echo $html;
?>
注意:这是我头脑中写的未经测试的,可能有一些错误,但主路径应该是清晰的。你是说卡住了,不是堆栈?你收到任何错误消息了吗?能否在$orders=array之前发布var_dump$results insert的结果;行?当我将它更改为打印\r$结果时,它只是打印布尔法尔斯;它也没有显示任何东西,我只是解决了它。但我还需要更多。我想计算总价格,然后在发票底部显示它。我需要的只是如何将其放入表中,因为我可以从表中的另一行列中获取数据。例如:对于每个id_购物车,总计=60.000。查看问题中上面的更新表,我还希望id_cart的每个结果都被包装,这样我就可以在每个单独的块上设置边框样式,看起来与上面的示例相同。帮助
<?php
include ("config.php");
$results = $mysqli->query
("
SELECT DISTINCT orders_history.transaction_id,
orders_history.items,
orders_history.quantity,
orders_history.one_product_price
FROM orders_history, orders_list
WHERE orders_history.transaction_id = orders_list.transaction_id
AND orders_list.customer_name = 'Klaudia'"
);
$orders = array();
$html = '';
if ($results) {
while($obj = $results->fetch_object()) {
$orders[$obj->transaction_id][$obj->items] = array('quantity' => $obj->quantity, 'invoices' => $obj->one_product_price);
}
$html .= '<table><tr>';
$html .= '<th>id_cart</th>';
$html .= '<th>products</th>';
$html .= '<th>quantity</th>';
$html .= '<th>invoices</th></tr>';
foreach ($orders AS $order_id => $order) {
$html .= '<tr><td rowspan="' . count($order) . '">' . $order_id . '</td>';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) { $html .= '</tr><tr>'; }
$html .= '<td>' . $item . '</td>';
$html .= '<td>' . $data['quantity'] . '</td>';
$html .= '<td>' . $data['invoices'] . '</td>';
/* INSERTED CODE FOR STATUS */
if ($row == 1) {
$html .= '<tr><td rowspan="' . count($order) . '">' . $status . '</td>';
}
/* END OF INSERTION */
$row++;
}
$html .= '</tr>';
}
$html .= '</table>';
}
echo $html;
?>