sql echo tables code example
Example 1: query sql in php
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
Example 2: showing database table in php
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('hrmwaitrose');
$query = "SELECT * FROM employee";
$result = mysql_query($query);
echo "<table>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>";
}
echo "</table>";
mysql_close();