user2952715
user2952715

Reputation: 31

Print two columns array into HTML table

I have the following Query that I have to display in a HTML table:

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

When running the query in PHPMYADMIN, it works perfectly as I need but I can't figure out how to get the same result on a html table.

That's how is displayed in phpmyadmin:

Any help will be much appreciated.

Upvotes: 0

Views: 134

Answers (2)

Jenz
Jenz

Reputation: 8369

$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';

Upvotes: 1

Shaunak Shukla
Shaunak Shukla

Reputation: 2347

    $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);

Upvotes: 1

Related Questions