Hi everyone, I'm working on a new project and I can sense that I'll be spending quite a bit of time on here!
My first stumbling block is a dropdown list I'm trying to create. I have a database populated with and ID, a category ID, a title and a description. Each category can belong to any other category (so, say I have 'Seeds' with an ID of 1 and 'flower seeds' with an ID of 2, category ID of 1 and similarly 'vegetable seeds' with an ID of 3, category ID of 1 - that way flower and vegetable seeds come under the heading of seeds). So, in other words I have created a simple category/subcategory system. Now.........what I'm trying to do is populate a dropdown menu with said categories/subcategories whilst keeping each subcategory directly below its parent. The code I have so far is.......
<?php
$sql = "SELECT * FROM shop_categories";
$result = mysql_query($sql, $conn);
while ($array = mysql_fetch_array($result))
{
$parent = $array['cat_parentid'];
$level = $array['cat_level'];
$title = $array['cat_title'];
$id = $array['id'];
if ($parent == 0)
{
echo "<option name=\"parent\" value=";
echo $id;
echo ">";
echo $title;
echo "</option>\n";
}
elseif ($level == 1)
{
echo "<option name=\"parent\" value=";
echo $id;
echo ">";
echo " ";
echo $title;
echo "</option>\n";
}
}
?>
(it's easier than I'm explaining it!!). Actually, I'll pop a link to the page for you......
Link.
So.....basically I would like the subcategory 'under seeds' to be......well, underneath the seeds main category. I can see why it's not working with my loops - but I can't quite work out how to rectify it.
The whole elseif level == 1 bit is to make the subcategory have a couple of spaces before to separate them from the root categories, that way I can hopefully have several layers of subcategories to drill down.
I'm really sorry, I'm having problems explaining myself today! I hope someone can make sense of my ramblings.
Many thanks,
Rich.