Jump to content

previous tag problem need a workaround pls


jacko_162

Recommended Posts

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.