我需要你的帮助,我有这个表(图片),我想把这些数据放在每行的列中,就像这个fiddle,但我不知道如何,我只知道显示在与db table(rows)相同的方式。 你知道我该怎么办?
这是我使用MySQL的show数据的方式:
<?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>";
?>
我希望你理解,谢谢。
答案 0 :(得分:1)
假设您正在询问如何将表格侧向翻转:将值存储在数组中,然后每行回显每个数组的内容,如下所示:
<?
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>";
?>