How can PHP be used to categorize members in a database?
To categorize members in a database using PHP, you can query the database for the members and then classify them based on certain criteria such as age, location, interests, etc. You can then display the categorized members on a webpage or perform further actions based on their category.
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "members_db";
$conn = new mysqli($servername, $username, $password, $dbname);
// Query the database for members
$sql = "SELECT * FROM members";
$result = $conn->query($sql);
// Categorize members based on age
while($row = $result->fetch_assoc()) {
if($row['age'] < 18) {
echo $row['name'] . " - Child";
} else {
echo $row['name'] . " - Adult";
}
}
// Close the database connection
$conn->close();