php mysql show data in table code example

Example 1: query sql in php

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();

Example 2: show table mysql

# First, select your database
USE yourDb;

# Then, simply
SHOW TABLES;

Example 3: show tables mysql

Press CTRL+C to copy SHOW [EXTENDED] [FULL] TABLES
    [{FROM | IN} db_name]
    [LIKE 'pattern' | WHERE expr]

Example 4: MySQL SELECT

SELECT select_list
FROM table_name;

Tags:

Sql Example