I have the following code:
// Create Connection
$mysqli = new mysqli($host, $username, $password, $db_name);
//Check connection
if($mysqli->connect_error){
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected Successfully";
// Retrieve data from database
$result= $mysqli->query("SELECT * FROM scores ORDER BY score DESC LIMIT 10");
Basically I need to know how to handle this data now. In the database I have a format:
Column 1: Name
Column 2: HighScore
I'm trying to display this on a webpage in a table so I need the query in a format which I can handle, what I have so far is:
// Start looping rows in mysql database.
while($rows=mysqli_fetch_array($result)){
echo $rows['name'] . "|" . $rows['score'] . "|";
// close while loop
}
However, I don't believe I am using the mysqli_fetch_array()
correctly as it isn't entering the while loop.