jacko_162 Posted August 6, 2011 Share Posted August 6, 2011 OK in a previous post i discussed how i would go about adding product tags to my CMS system, This has now been coded and implimented by myself, the ability to add, view and delete is now done. i have a tag list page, which lists the tags like so: A ------ "Tag Name" "Tag Name" "Tag Name" "Tag Name" B ------ "Tag Name" "Tag Name" "Tag Name" etc. the above is coded using: <?php $qry = "SELECT tag, LEFT(tag, 1) AS first_char FROM tags WHERE UPPER(LEFT(tag, 1)) BETWEEN 'A' AND 'Z' OR LEFT(tag, 1) BETWEEN '0' AND '9' ORDER BY tag"; $result = mysql_query($qry); $current_char = ''; while ($row = mysql_fetch_assoc($result)) { if ($row['first_char'] != $current_char) { $current_char = $row['first_char']; echo '<br /><br /><span class="bigtag">' . strtoupper($current_char) . '</span><br />---------------<br />'; } $tagname = $row['tag']; echo "<div class='tag tag-left'>"; echo "<div class='left'></div>"; echo "<div class='center'><a href='product_tag.php?tag=$tagname'>"; echo $row['tag'] . ''; echo "</a></div>"; echo "<div class='right'></div></div>"; } ?> now problem i have is sometimes tags are duplicated, for instance atm i have the colour "Red" tagged 5 times, and it appears 5 times under the "R" column using above layouts. R ------ "Red" "Red" "Red" "Red" "Red" How can i limit it to show only the once please? Link to comment https://forums.phpfreaks.com/topic/244037-previous-tag-problem-need-a-workaround-pls/ Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 try... $qry = "SELECT DISTINCT tag, LEFT(tag, 1) AS first_char FROM tags WHERE UPPER(LEFT(tag, 1)) BETWEEN 'A' AND 'Z' OR LEFT(tag, 1) BETWEEN '0' AND '9' ORDER BY tag"; notice the use of the keyword 'DISTINCT' to select unique rows. Link to comment https://forums.phpfreaks.com/topic/244037-previous-tag-problem-need-a-workaround-pls/#findComment-1253279 Share on other sites More sharing options...
jacko_162 Posted August 6, 2011 Author Share Posted August 6, 2011 so simple thx Link to comment https://forums.phpfreaks.com/topic/244037-previous-tag-problem-need-a-workaround-pls/#findComment-1253326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.