0

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.

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, so far I get only the titles SUMA & country
@user2952715, I've updated my answer.. Is there any error you getting?
Both the answer looks similar, if your answer was first and correct than why other people post same answer again. up vote from my side for your answer
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 Comment

I get an error in the following line, seems because of the single quotes echo "<tr><td>$row['suma']</td><td>$row['country']</td></tr>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.