Im a newb to php and programming in general, so bare with me guys
I have two arrays, one with categories, and the other with articles. If the category array has corresponding articles in the articles array, I want the category name and the corresponding articles to be displayed.
If a category has no articles, then it is not displayed.
Here's an example:
--You have two categories in the category array: news and sports
--You have four articles in the article array, all of which belong to the sports category
--OUPUT: The code only displays the sports category with the sports articles, since there are no news articles
The code I have written thus far displays the category name regardless of whether or not a category has corresponding articles. I'm having trouble writing a method that checks whether a category has articles.
Does anyone know of a way I can compare the two arrays to get the desired output? Any help would be greatly appreciated!
PHP Code:foreach($categories as $row1)
{
$cat_id = $row1['id'];
echo '<br>';
echo '<br>';
echo $row1['name'];
echo '<br>';
foreach($art_array as $row2)
{
$artcatid = $row2['category'];
if ($cat_id == $artcatid)
{
$title = $row2['headline'];
echo '<li>';
echo $title;
} //if
}//foreach
}//foreach




Bookmarks