Im setting up a website for my home work and I need to display 1 row at random from an sql table in a html table using php. For example, my website is called random data where the website will generate random data for you (except all it is actually doing is displaying data already inserted into a database). So, does anyone know the code required to display 1 row of data from an sql table and display it in a html table using php in each cell of the table to retrieve the data from the database? Here is what I have so far (it works when I don't try to select just one row at random, but when I select all of them, it does work. Pleas Help! :)
<?php
$username = "root";
$password = "root";
$dbname = "fakedeets";
$conn = new mysqli("localhost", $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT FLOOR(RAND()*(10-5+1)+5);";
$result = $conn->query($sql);
if($row = $result-> fetch_assoc()) {
echo "<tr><td>". $row["firstname"].
"</td><td>". $row["lastname"].
"</td><td>". $row["dob"].
"</td><td>". $row["gender"].
"</td><td>". $row["emailaddress"].
"</td><td>". $row["phonenumber"].
"</td><td>". $row["photo"].
"</td></tr>";
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
What I expect to appear is just 1 row of data displayed on a html doc selected at random from an sql database. Instead it just outputs nothin
Your Fake Deets Are: