I want the following information pulled from a database and layed out exactly like this is a drop down menu:
Select Category
Bread Brands (5)
Cereal Brands (8)
Milk Brands (2)
The number represents how many matching results I will find if I was to select that certain category. What kind of result would I have to write to count those rows and display them next to their name?
I know how to do pull the name from the mysql db but I need to write an additional query or function to count the rows of each result. Here is my code:
<form method="GET" action="series.php">
<tr>
<td width="113"><font face="Arial" size="2">Select a Series:</font></td>
<td align="left"><select size="1" name="subcatid">
<?php
$maincatid = $_GET['maincatid'];
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM subcat WHERE maincatid = '$maincatid'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)) {
echo '<option selected value="' . $row['subcatid'] . '">' . $row['subcatname'] . '</option>';
}
Select Category
Bread Brands (5)
Cereal Brands (8)
Milk Brands (2)
The number represents how many matching results I will find if I was to select that certain category. What kind of result would I have to write to count those rows and display them next to their name?
I know how to do pull the name from the mysql db but I need to write an additional query or function to count the rows of each result. Here is my code:
<form method="GET" action="series.php">
<tr>
<td width="113"><font face="Arial" size="2">Select a Series:</font></td>
<td align="left"><select size="1" name="subcatid">
<?php
$maincatid = $_GET['maincatid'];
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM subcat WHERE maincatid = '$maincatid'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)) {
echo '<option selected value="' . $row['subcatid'] . '">' . $row['subcatname'] . '</option>';
}