I have 3 simple tables linking information. Lets call them product, category and assignment. These tables tie information together. For example a set of data like this:
product
id, name
1, small toy
2, middle sized toy
3, big toy
category
id, class
1, boy
2, girl
assignment
id, productID, ClassID
1, 1, 1
2, 2, 2
3, 2, 1
4, 3, 2
The result here is that the big toy is for girls, the middle sized toy is for a boy or a girl, and the small toy is for a boy.
No I can't figure out how to generate a list that doesn't end up with duplicates. I'm getting this:
What I want is this:
- boy
- small toy
- middle sized toy
- girl
Here's the code:
PHP Code:
<?php
$sql = "SELECT *
FROM product, category, assignment
WHERE class.id = assignment.classID
AND product.id = assignment.productID
ORDER BY category.id
";
$result = mysql_query($sql);
echo '<ul>';
if (mysql_num_rows($result) > 0) {
while ($rec = mysql_fetch_assoc($result)) {
echo '<li />' , $rec['class'], ' <ul><li />', $rec['name'],
'<ul>';
}
}
echo '</ul>';
}
?>
I've been looking for a way to keep the category from repeating that still allows the product to repeat. Any ideas would be appreciated.