Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.