I'm in the process of making a website that handles an online highscore list for an application that I've made. The site is pretty much up and running, using prepared statements to insert names and scores from the user application. But I have bumped into a problem when it comes to using a prepared statement for fetching data from the database. Here's my code for fetching an displaying:
$display = $db->prepare("SELECT * FROM highscores ORDER BY score DESC");
$display->execute();
$result = $display->get_result();
$i = 1;
while ( $row = mysqli_fetch_array($result) ) {
if ($i % 2 != 0) {
echo "<div id = 'odd'>";
echo "<div id = 'l'>" . $i . "</div>";
echo "<div id = 'r'>" . $row['score'] . "</div>";
echo "<div id = 'c'>" . $row['name'] . "</div>";
echo "</div>";
}
else {
echo "<div id = 'even'>";
echo "<div id = 'l'>" . $i . "</div>";
echo "<div id = 'r'>" . $row['score'] . "</div>";
echo "<div id = 'c'>" . $row['name'] . "</div>";
echo "</div>";
}
$i++;
}
$display->close();
$db->close();
This works just fine on my local server that I use for testing. However, I can't use this because get_result()
is only available with mysqlnd
which my website server does not support. I would be very happy if anyone could point me in the right direction or give me some advice on the matter.
Is it even necessary to use a prepared statement in this scenario?