Loading...
start the course

Learn PHP

Codes and notes

INSERT DATA INTO TABLE
Back Next

we can select data recoded in table.

syntax
<?php
$sql = "SELECT id, firstname, lastname FROM [table name]";
$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"]. "
";
}

} else { echo "0 results"; }

$conn->close();
? >

Back Next

Code editor

    <!DOCTYPE html>
    <html>
    <body>

    <?php
    
    # select statement in php
    
            
        $sql
        
        = "SELECT id, firstname, lastname FROM [table name]";

        
        
        
$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"]. ";
}
} else { echo "0 results"; } $conn->close(); ?> </body> </html>

Output