Mysql
 SQL >> Database >  >> RDS >> Mysql

Stampare risultati query in tabella HTML con PHP

Per mostrare i risultati di una query MySQL in una tabella HTML, puoi scorrere le righe e stampare i valori nelle celle:

$result = mysqli_query($conn, "SELECT subject, actions FROM info WHERE category='$find' ORDER BY votes DESC");

if (mysqli_num_rows($result) > 0) {
    echo "<table>";
    echo "<tr><th>Soggetto</th><th>Azioni</th></tr>";

    while ($row = mysqli_fetch_assoc($result)) {
        echo "<tr>";
        echo "<td>" . htmlspecialchars($row['subject']) . "</td>";
        echo "<td>" . htmlspecialchars($row['actions']) . "</td>";
        echo "</tr>";
    }

    echo "</table>";
}

In progetti moderni è preferibile usare PDO o mysqli con prepared statement.