将两列数组打印到HTML表中

时间:2014-09-15 09:48:40

标签: php html arrays html-table

我有以下查询,我必须在HTML表格中显示:

$query= "SELECT SUM(amount_pln) AS suma,country FROM fin_revenues GROUP BY country ORDER BY suma DESC";
$result = mysqli_query($mysqli,$query);

在PHPMYADMIN中运行查询时,它可以完美地运行,但我无法弄清楚如何在html表上获得相同的结果。

这就是phpmyadmin中的显示方式:

http://oi59.tinypic.com/2ajdjtg.jpg

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

$query= "SELECT SUM(amount_pln) AS suma,country FROM fin_revenues GROUP BY country ORDER BY suma DESC";
$result = mysqli_query($mysqli,$query);
echo '<table>
        <tr>
          <td>Suma</td>
          <td>Country></td>
       </tr>';
while($row=mysqli_fetch_array($mysqli,$result))   // while there are records
{
    echo "<tr><td>".$row['suma']."</td><td>".$row['country']."</td></tr>";   // echo the table with query results
}
echo '</table';

答案 1 :(得分:1)

    $query= "SELECT SUM(amount_pln) AS suma,country FROM fin_revenues GROUP BY country ORDER BY suma DESC";
    $result = mysqli_query($mysqli,$query);

    echo "<table><tr><td>SUMA</td><td>country</td></tr>";

    while($row = mysqli_fetch_assoc($result)){
    echo "<tr><td>".$row['suma']."</td><td>".$row['country']."</td></tr>";
    }
echo "</table>";
mysqli_free_result($result);