
I have a database from which i want to retrieve an <UL> of categories which correspond to the DISTINCT unique category names. So,for each differently named category_name field in my DB i want to create an <UL> with a <h2> title corresponding to the category name.Then,i want to create 5 <LI> elements inside of each of the created UL that are put under the same category_name field.
Everything works well with creating UL untill i put in my code to create <LI> elements inside those UL.If i put in the code for creating LI,then the whole code creates only ONE UL with 5 corresponding <LI> elements of that UL.
My code is this:
- Code: Select all
<?php
$query1 = "SELECT DISTINCT `category_name` FROM `links`";
if ($query_run = mysql_query($query1)) {
while($row = mysql_fetch_assoc($query_run)) {
$title = $row['category_name'];
echo "<div class=\"category\">
<h2>$title</h2>
<ul>";
$query2 = "SELECT `image`,`link_description`,`link` FROM `links` WHERE `category_name`='$title' LIMIT 5";
if ($query_run = mysql_query($query2)) {
while($row = mysql_fetch_array($query_run)) {
$tutorial_image = $row['image'];
$tutorial_desc = $row['link_description'];
$tutorial_link = $row['link'];
echo "<li><a href=\"$tutorial_link\" target=\"_blank\"><img src=\"images/$tutorial_image.png\" alt=\"$tutorial_image tutorial\"/>$tutorial_desc</a></li>";
}
}
echo "</ul>
<div class=\"view_all\">
<div class=\"view_all_inner\">
<img src=\"images/doubleArrow.png\" alt=\">>\"/>
<a href=\"#\">view all</a>
<div class=\"clear\"></div>
</div>
</div>
</div>";
}
}
?>
Can anyone see where the problem with the code logic is? I would be grateful if you can help me



