I am trying to make a page that displays articles in a database but it is to be organised in by category.
The categories are stored in a table categories
with id and category as its fields/
The articles are stored in a table articles
with its different fields for various information about the article.
The code I have:
<?php
$sql = "SELECT * FROM `categories`";
$query = mysql_query($sql) or die("Could not get CATEGORIES ".mysql_error());
while($category = mysql_fetch_array($query)){
$cat = $category['category'];
$sql = "SELECT * FROM `articles` WHERE `category` = '$cat'";
$query = mysql_query($sql) or die(mysql_error());
$articles = mysql_fetch_array($query);
$size = count($articles);
echo $size;
}
?>
Results that I expect are a list of each category, then underneath each category, the number of articles with that category.
Some help would be much appreciated.
Thanks :D