Not sure this is an architecture question or not, please fix if i am wrong,
ok i have a arrays ( by using a foreach )
foreach ($db['products'] as $product)
{
echo '<li><a href="">' . $product['tag'] . '</a></li>';
}
// displays like
tag1
tag4
tag2
tag2
tag1
tag3
tag1
tag1
tag3
tag2
tag3
tag2
do anyone have an idea how to show
//count tags & no duplicate tags ?
tag1(4)
tag2(4)
tag3(3)
like stackoverflow have ?
edit one ( PDO )
$database->fetchall("SELECT pid, uid, name, information, image_tumb, tag, price
FROM products ORDER BY pid DESC LIMIT 100");
edit two when i do this
$db['products'] = $database->fetchall("SELECT pid, uid, name, information, image_tumb, tag, price
FROM products GROUP BY tag ORDER BY pid DESC LIMIT 100");
it does work, but some products are not displaying.
- all product is displayed
- but the tags are just like above.
thanks for your time btw, its save my learning time alot.
edit* it work. thanks all
$db['products'] = $database->fetchall("SELECT pid, uid, name, information, image_tumb, price
FROM products ORDER BY pid DESC LIMIT 100");
$db['tags'] = $database->fetchall("SELECT tag, COUNT(tag) AS counter
FROM products GROUP BY tag ORDER BY tag DESC LIMIT 100");
foreach ($db['tags'] as $tag) {
echo '<li><a href="">' . $tag['tag'] . '(' . $tag['counter'] . ')</a></li>';
}
buy doing this i still get all of my products with a list of tags no duplicate + counter. thanks again!.
You can either use an array to remember the items that already have been displayed:
Or you sort the array in advance and just compare the current item with the previous one:
But you can probably do the same within your database query and just grab the results like: