I want to insert data which returns from the php code, into an existing html table (name = "userDetails").
Number of rows in the html table would be different according to the results receiving from the mysql database. How can I do that?
Code is as follows,
<?php
$connection = mysqli_connect('localhost', 'root', '', 'users');
$sql = "SELECT id, firstname,email FROM usertable";
$result = mysqli_query($connection, $sql);
$userDetailsArray = array();
if(mysqli_num_rows($result) > 0){
$index = 0;
while ($row = mysqli_fetch_assoc($result)) {
$userDataArray[$index] = $row;
$row = $userDataArray[$index];
$userID = $row['id'];
$firstName = $row['firstname'];
$email = $row['email'];
$index++;
}
}
?>
<html>
<head></head>
<body>
<table name = "userDetails">
<tr>
<th>User ID</th>
<th>First Name</th>
<th>email</th>
</tr>
</table>
</body>
<html/>