I have the following PHP code which selects 10 random people from the "network" table saying they have joined the chat:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM network ORDER BY RAND() LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["name"]. " has joined the chat <br>";
}
} else {
echo "0 results";
}
$conn->close();
However, instead of just showing the full list of the 10 people, I want it to show each one individually for one second and fade between them. I have the following JQuery function to do this display, but I don't understand how to combine these. How do I put the 10 random records from the table into this function?
(function() {
var timesRun = 0;
var runLimit = 10;
var RandomPeople = [NEED THE 10 RECORDS FROM THE DATABASE ABOVE TO GO HERE],
i = 0;
setInterval(function() {
timesRun += 1;
if (timesRun < runLimit) {
$('#changing-word').fadeOut(function() {
$(this).html(RandomPeople[i = (i + 1) % RandomPeople.length]).fadeIn();
});
}
}, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<span id="changing-word">Random Person's Name</span> has joined the chat.