I'm back again. :rolleyes:
I'm up to extending the code we worked out last week so that I now gives me all the correct details I want. The first part was easy. I added some fields to the query, added a few lines to the output, and I now have a correct combination of headings and descriptions. Yay me. 🙂
I have one last problem, however. Each category has two images associated with it that just help jazz up the page a little if there's lots of content. I don't want to overload the page with unnecessary pictures, though, so I want to write some code to do the following:
- If a category has at least two sections selected, it also displays the first image.
- If a category has at least four sections selected, it also displays the second image.
So, for example:
Category 1
- Section 1
- Section 2
- Section 3
- Section 4
Category 2
- Section 5
- Section 6
- Section 7
Category 1 will show two pictures and Category 2 will show one.
At the moment I have the following code:
$sql = "SELECT c.CategoryName AS n, c.TitleImage AS t, c.Image1 AS p1, c.Image2 AS p2, s.SectionName AS l, s.Description AS d
FROM category c INNER JOIN section s USING (CategoryID)
WHERE s.ID IN ($list2)
ORDER BY n, l";
$result3 = mysql_query($sql);
$number = mysql_num_rows($result3);
$curr = "";
while ($row3 = mysql_fetch_array($result3)) {
if ($row3['n'] != $curr) {
echo "<img src=\"" . $row3["t"] . "\" alt=\"" . $row3["n"] . "\" class=\"titleImage\" />";
echo "<h2>" . $row3['l'] . "</h2>";
if ($number >= 2) {
echo "<img src=\"" . $row3["p1"] . "\" />";
}
echo $row3['d'];
$curr = $row3['n'];
} else {
echo "<h2>" . $row3['l'] . "</h2>";
echo $row3['d'];
}
}
Unsurprisingly, this doesn't quite do what I want because I gets the number of results in the whole query instead of just for the current category.
Can anyone suggest a way I can easily get the number of results for a single category and use that as a comparison?
Cheers,
Seona.