I am trying to display multiple parts of a query on my page using fetch_assoc and some conditional statements. My first while loop is displaying the correct information, but loops 2 and 3 are not displaying any information. What would be the correct way to filter my results?
require_once('inc/connection.inc.php');
//create database connection
$conn = dbConnect();
//create SQL
$sql = 'SELECT * FROM menu';
$result = $conn->query($sql) or die(mysqli_error());
while($row = $result->fetch_assoc()){ if($row['category'] == 'appetizers'){ echo $row['title']; echo $row['price']; }
}
while($row = $result->fetch_assoc()){ if($row['category'] == 'salads'){ echo $row['title']; echo $row['price']; }
}
while($row = $result->fetch_assoc()){ if($row['category'] == 'desserts'){ echo $row['title']; echo $row['price']; }
}