I have a database with prices of mangos, apples, and oranges, arranged by date.
I want to filter the prices in a table by ID. I'm able to filter the results using one ID, and display them in a table.
How can I filter by more than one ID value using WHERE in SQL, and display the resulting data in tabular form?
<table style="float:left;">
<tr>
<th>Mango </th>
<th>Apple</th>
<th>Orange </th>
<th>Date</th>
</tr>
<?php
$dbhost ="localhost"; // hostname
$dbuser="root"; // mysql username
$dbpass="****"; // mysql password
$db="****"; // database you want to use
$conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db ) or die("Could not connect: " .mysqli_error($conn) );
$sql = "SELECT MANGO, APPLE, ORANGE, DATE FROM dataTable WHERE ID='3' ORDER BY Date DESC LIMIt 1";
$result = $conn->query ($sql);
if($result ->num_rows>0){
while($row = $result ->fetch_assoc()){
echo "<tr><td>". $row["MANGO"]."</td><td>".$row["APPLE"]."</td><td>".$row["ORANGE"]."</td><td>".$row["DATE]."</td> </tr>";
}
echo "</table>";
}else {echo "0 result";}
$conn->close();
?>
</table>