I tried to make a multilevel of list. For example, I need a list of books divided by categories like:
Category: Since.
Tilte1
Tilte2
Category: History
Tilte1
Tilte2
What I have is:
Category: Since.
Tilte1
Category: Since.
Tilte2
Category: History
Tilte1
Category: History
Tilte2
I wrote this code:
$sql = "SELECT books.title, books.categoryid, categories.id, categories.category FROM books, categories
WHERE books.categoryid = categories.id
ORDER BY books.categoryid
";
$result = mysql_query($sql, $connection);
$dsp = "<ul>";
while ($row = mysql_fetch_array($result))
{
$title = $row['title'];
$category = $row['category'];
$dsp .= "<li><b>$category</b>";
if ($categoryid = $id)
{
$dsp = "<ul>";
While ($row = mysql_fetch_array($result))
{
$dsp .= "<li>$title";
}
$dsp = "</ul>";
}
}
$dsp .= "</ul>";
echo ("$dsp");