For example,
Vehicles (30)
- Cars (15)
- Bikes (13)
- Other (2)
This can be done by querying the database. In this case, I am using MySQL.
Let’s assume that we are passing the category id in the URL. So,
- Get the category id from the URL
- Query the database with that id
- Build the query
- Get the resulting row
- Finally, get the count field from the resulting row (this is the data we want)
$cat = mysql_real_escape_string($_GET['category']);
$query = 'SELECT COUNT(*) as count FROM vehicles WHERE catId = '$cat'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$num_items_in_category = $row['count'];
No comments:
Post a Comment