I'm trying to get a list of items in a region.
I'd like the Region Name as a Heading Then all the items in that region in a table below i.e.
HEADING - Region1
Table - Region1 Items
HEADING - Region2
Table - Region2 Items
HEADING - Region3
Table - Region3 Items
HEADING - Region4
Table - Region4 Items
I can output:
HEADING
HEADING
HEADING
I can output the region details in a table if I use LIKE 'Actual Region Name'
I would like to output using LIKE $region so I don't need to write a new statement for each 'Actual Region Name'.
The 2 SELECT Queries:
$region = mysqli_query($conn,"SELECT DISTINCT region FROM country") or die($conn->error);
$result = mysqli_query($conn,"SELECT * FROM country WHERE region LIKE '$region'") or die($conn->error);
OUTPUT 1
This outputs each region as
Region Name
$i = 0;
while($row = $region->fetch_assoc())
{
if ($i == 0) {
foreach ($row as $value) {
echo "<p>" . $value . "</p>";
}
}
}
OUTPUT 2
This outputs all the region data and puts it in a table.
echo "This is table Build";
echo "<table border='1'>";
$i = 0;
while($row = $result->fetch_assoc())
{
if ($i == 0) {
$i++;
echo "<tr>";
foreach ($row as $key => $value) {
echo "<th>" . $key . "</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach ($row as $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
OUTPUT 1 and OUTPUT 2 both work separately. I can't get them to work together