Answers for "get data from mysql php"

PHP
17

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();
Posted by: Guest on February-05-2020
0

query-data-from mysql and php

<?php 
                            $sql = "SELECT * FROM `users`";
                            $result = mysqli_query($conn, $sql);
                            // fetch all users
                            $users = mysqli_fetch_all($result, MYSQLI_ASSOC);
                            ?>
                            <!-- A single user -->
                            <?php foreach ($users as $user): ?>
                                <tr>
                                    <td><?php echo $user['id'] ?></td>
                                    <td><?php echo $user['Name'] ?></td>
                                    <td><?php echo $user['Email'] ?></td>
                                    <td> <span id="user_current_status"></span></td>
                                </tr>
                            <?php endforeach; ?>
                            <!-- A single user -->
Posted by: Guest on August-03-2021

Browse Popular Code Answers by Language