gpt4 book ai didi

php - 将包含数据的列中的行从 MySQL 转置到 PHP

转载 作者:太空宇宙 更新时间:2023-11-04 13:07:55 25 4
gpt4 key购买 nike

我需要你的帮助,我有这张表(图片),我想像这样将数据按行放在列中 fiddle ,但我不知道如何,我只知道以与数据库表(行)相同的方式显示。你知道我该怎么做吗?

enter image description here

这是我使用的显示MySQL数据的方式:

<?php 
$sqlStr = "SELECT items.CA_id, items.item_id, items.item_Cant, items.CECO_cod, items.item_desc, items.item_enduser
FROM items where CA_id = ".$CA_id;
$sqlStrAux = "SELECT count(*) as total FROM items";

$aux = Mysql_Fetch_Assoc(mysql_query($sqlStrAux));
$query = mysql_query($sqlStr);

if($aux['total']>0){

echo "</br></br>";
echo "<div class='datagrid'>";
echo "\t<table class=\"tablesorter\">\n";
echo "<thead>";
echo "<tr>
<th>Item</th>
<th>Cantidad</th>
<th>CECO</th>
<th>Descripción de solicitud</th>
<th>Usuario final</th>
</tr>\n";
echo "</thead>";
echo "<tbody>";
while($row = mysql_fetch_assoc($query)){
echo "\t\t<tr>
<td>".htmlentities($row['item_id'])."</td>
<td>".htmlentities($row['item_Cant'])."</td>
<td>".htmlentities($row['CECO_cod'])."</td>
<td>".$row['item_desc']."</td>
<td>".$row['item_enduser']."</td>
</tr>\n";
}
echo "</tbody>";
echo "\t</table>\n";
}
echo "</div>";
?>

希望您能理解,谢谢。

最佳答案

假设您要问如何横向翻转表格:将值存储在数组中,然后每行回显每个数组的内容,如下所示:

<?
while($row = mysql_fetch_assoc($query)){
$itemID[] = htmlentities($row['item_id']);
$item_Cant[] = htmlentities($row['item_Cant']);
$CECO_cod[] = htmlentities($row['CECO_cod']);
$item_desc[] = $row['item_desc'];
$item_enduser[] = $row['item_enduser'];
}
echo "<table>";

echo "<tr><td>Item ID</td>";
for ($i=0; $i<count($itemID);$i++) {
echo "<td>".$itemID[$i]."</td>";
}
echo "</tr><tr><td>Item Can't</td>";
for ($i=0; $i<count($item_Cant);$i++) {
echo "<td>".$item_Cant[$i]."</td>";
}
echo "</tr><tr><td>Next row title...</td>";
...
...
echo "</table>";
?>

关于php - 将包含数据的列中的行从 MySQL 转置到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24941437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com