如何在HTML Horizo​​ntal表中显示mysql查询输出

时间:2014-11-10 03:23:20

标签: php html mysql database

这是我的查询......

$sql20 = "SELECT size, SUM(sizeorderqty) as oqty FROM `colsize_tbl` WHERE Style_no='4320'";  

这些是为在html表中显示输出而编写的PHP代码

<?php
echo "<table border='1' cellpadding='3' cellspacing='0'> ";
while ($row20=mysql_fetch_array($result20)){
echo "<tr>";
echo "<td> Size </td>";
echo "<td>" . $row20['size']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td> Order Qty </td>";
echo "<td>" . $row20['oqty']."</td>";
}
echo "</tr>";
echo "</table>";
?>

但我的输出是

Size      | L   |
Order Qty | 300 |
Size      |M    |
Order Qty |250  |
Size      |S    |
Order Qty |500  |

请建议我以下列格式显示上表

Size       | S   | M   | L   |
Order Qty  | 500 | 250 | 300 |

2 个答案:

答案 0 :(得分:0)

您的HTML标记似乎有点无效。

由于我无法在没有您的数据库的情况下在本地运行代码,您能告诉我这是否有效吗?

这是您的查询:

$sql20 = "SELECT size, SUM(sizeorderqty) as oqty FROM `colsize_tbl` WHERE Style_no='4320'";

这是在HTML表格中显示输出的PHP代码:

<?php
    echo "<table border='1' cellpadding='3' cellspacing='0'>";
    $sizes = array();
    $oqtys = array();
    while ($row20 = mysql_fetch_array($result20)) {
        $sizes[] = $row20['size'];
        $oqtys[] = $row20['oqty'];
    }
    echo "<tr>";
    echo "<td>Size</td>";
    foreach($sizes as $size) {
        echo "<td>" . $size . "</td>";
    }
    echo "</tr><tr>";
    echo "<td>Order Qty</td>";
    foreach($oqtys as $oqty) {
        echo "<td>" . $oqty . "</td>";
    }
    echo "</tr></table>";
?>

答案 1 :(得分:0)

<?php
echo "<table border='1' cellpadding='3' cellspacing='0'> ";
echo "<tr>";
echo "<td> Size </td>"
while ($row20=mysql_fetch_array($result20)){
echo "<td>" . $row20['size']."</td>";
}
echo "</tr>";
echo "<tr>";
echo "<td> Order Qty </td>"
while ($row20=mysql_fetch_array($result20)){
echo "<td>" . $row20['size']."</td>";
}
echo "</tr>"
echo "</table>";
?>

=============================================== ================================= OUTPUT就像那样

尺寸| S | M | L |

订购数量| 500 | 250 | 300 |