早上好,我需要一些帮助,我将不胜感激。我有一张如下所示的表格:
但我希望它看起来像这样,以便用户更容易阅读:
我如何将其更改为那样?这是当前代码:
<?php
$sql = "SELECT
companyname,
ordernumber,
equipment,
theserial,
type,
theaddress
FROM table";
$result = mysqli_query($con, $sql);
?>
<table id="moreinfotable" name="moreinfotable" class="table table-bordered" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>OrderNumber</th>
<th>Equipment</th>
<th>Serial</th>
<th>Type</th>
<th>Address</th>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result)) {
$companyname = $row['companyname'];
$ordernumber = $row['ordernumber'];
$equipment = $row['equipment'];
$theserial = $row['theserial'];
$type = $row['type'];
$theaddress = $row['theaddress'];
echo '<tr>';
echo '<td>' . $companyname . '</td>';
echo '<td>' . $ordernumber . '</td>';
echo '<td>' . $equipment . '</td>';
echo '<td>' . $theserial . '</td>';
echo '<td>' . $type . '</td>';
echo '<td>' . $theaddress . '</td>';
echo'</tr>';
}
?>
</table>
对于固定的类型列表(此处为新的送货和取货),您可以使用条件聚合直接在 SQL 中转换数据集:
select companyname, ordernumber, address,
max(case when type = 'New Delivery' then equipment end) as delivery_equipment,
max(case when type = 'New Delivery' then serial end) as delivery_serial,
max(case when type = 'Pickup' then equipment end) as pickup_equipment,
max(case when type = 'Pickup' then serial end) as pickup_serial,
from mytable
group by companyname, ordernumber, address
我不确定,但您是否尝试订购您的查询? 例如:
SELECT * FROM exam ORDER BY exam_date;
这意味着从考试中选择所有内容并按考试日期排序。
"SELECT
companyname,
ordernumber,
equipment,
theserial,
type,
theaddress
FROM table
ORDER BY theaddress"