What are the recommended methods for sorting and displaying mission data in a list format using PHP and MySQL in a browser game?

When displaying mission data in a browser game, it is important to sort the missions based on certain criteria such as mission type, difficulty, or completion status. To achieve this, you can use PHP to query the mission data from a MySQL database and then sort it accordingly before displaying it in a list format on the game interface.

<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Query mission data from the database and sort it by mission type
$sql = "SELECT * FROM missions ORDER BY mission_type";
$result = $conn->query($sql);

// Display the sorted mission data in a list format
if ($result->num_rows > 0) {
    echo "<ul>";
    while($row = $result->fetch_assoc()) {
        echo "<li>" . $row["mission_name"] . " - Type: " . $row["mission_type"] . " - Difficulty: " . $row["difficulty"] . " - Status: " . $row["completion_status"] . "</li>";
    }
    echo "</ul>";
} else {
    echo "No missions found.";
}

// Close database connection
$conn->close();
?>