Adding <li> <ul> tags to loops
Moderator: General Moderators
Adding <li> <ul> tags to loops
edited
Last edited by Addos on Tue Aug 12, 2008 1:52 pm, edited 1 time in total.
-
www.WeAnswer.IT
- Forum Newbie
- Posts: 24
- Joined: Wed Mar 19, 2008 6:33 pm
Re: Adding <li> <ul> tags to loops
You were pretty close. Try this out:
Also, in the last chunk of code you posted, these lines had an error:
The part that says $xProducts = mysql_fetch_row($xProducts); should say $xProduct = mysql_fetch_row($xProducts);. There are some other issues with that code, such as minimizing the number of queries that the script imposes on the database, but the code I posted above should be alright for your purposes.
Code: Select all
<ul>
<?php
$output = '';
mysql_select_db($database_*****, $*****);
$xHeadings = mysql_query("SELECT *
FROM tbl_prdtcategories
WHERE category_archive = 0 ");
while($xHeading = mysql_fetch_assoc($xHeadings)) {
$output .= '<li>'.'<a href="results.php?category=' . $xHeading['category_ID'] . '">' . $xHeading['category_Name'] .'</a><ul>';
$xProducts = mysql_query("SELECT *
FROM tbl_prdtcategories, tbl_products,tbl_prdtcat_rel
WHERE product_ID = prdt_cat_rel_Product_ID
AND product_Archive = 0
AND product_OnWeb = 1
AND category_ID = prdt_cat_rel_Cat_ID
AND category_Name = '$xHeading[category_Name]'
ORDER BY product_Name");
while($xProduct = mysql_fetch_assoc($xProducts)) {
$output .= '<li>'.'<a href="details.php?prodId=' . $xProduct['product_ID'] . '">' . $xProduct['product_Name'] .'</a>' .'</li>';
}
$output .= '</ul></li>';
}
print $output;
?>
</ul>Also, in the last chunk of code you posted, these lines had an error:
Code: Select all
$xProducts = mysql_fetch_row($xProducts);
if($xProducts)
{
$output[] = "<li><a href=\"details.php?prodId='{$xProduct['product_ID']}\">{$xProduct['product_Name']}</a></li>";
}Re: Adding <li> <ul> tags to loops
edited
Last edited by Addos on Tue Aug 12, 2008 1:53 pm, edited 1 time in total.
Re: Adding <li> <ul> tags to loops
edied
Last edited by Addos on Tue Aug 12, 2008 1:53 pm, edited 1 time in total.
-
www.WeAnswer.IT
- Forum Newbie
- Posts: 24
- Joined: Wed Mar 19, 2008 6:33 pm
Re: Adding <li> <ul> tags to loops
Ok, try this out. I have cleaned it up a little further so that it's easier to read the output.
Unfortunately I am not at my usual computer and I can't test it out for you.
Code: Select all
<ul>
<?php
$output = '';
mysql_select_db($database_*****, $*****);
$xHeadings = mysql_query("SELECT *
FROM tbl_prdtcategories
WHERE category_archive = 0 "
);
while($xHeading = mysql_fetch_assoc($xHeadings)) {
$output .= "\n\t<li>\n\t\t".'<a href="results.php?category=' . $xHeading['category_ID'] . '">' . $xHeading['category_Name'] .'</a>';
$xProducts = mysql_query("SELECT *
FROM tbl_prdtcategories, tbl_products,t bl_prdtcat_rel
WHERE product_ID = prdt_cat_rel_Product_ID
AND product_Archive = 0
AND product_OnWeb = 1
AND category_ID = prdt_cat_rel_Cat_ID
AND category_Name = '{$xHeading['category_Name']}'
ORDER BY product_Name"
);
if(mysql_num_rows($xProducts) > 0)
{
$output .= "\n\t\t<ul>";
while($xProduct = mysql_fetch_assoc($xProducts)) {
$output .= "\n\t\t\t<li>".'<a href="details.php?prodId=' . $xProduct['product_ID'] . '">' . $xProduct['product_Name'] .'</a>' .'</li>';
}
$output .= "\n\t\t</ul>\n\t</li>";
}
}
print $output;
?>
</ul>Unfortunately I am not at my usual computer and I can't test it out for you.