1
   $content = '<h3>popular tags »</h3><hr>';

    $result = $db->sql_query("SELECT tags FROM ".DOWNLOAD_TABLE." ");
    while($row = $db->sql_fetchrow($result)){
     $dl_tags_id = $row['tags'];
     $dl_tags_id_ex = explode(" ",$dl_tags_id)   ;
     $dl_tags_id = array_unique($dl_tags_id_ex);

     $c = count($dl_tags_id);
     for($i=1;$i<$c-1;$i++){
//for loop content

     }
    }
    echo $content;

Hey guys. I used the above code to show my popular tags. As you can see in the code, I have two tables, one is download table that stores tags ID in array format such as:

20 21 13 14

And the other one is tags table that define those IDs

Now the only problem is that when printing this code, I can see duplicated tags as:

white(2)
blue(4)
white(2)

I wonder how prevent showing duplicated output.

Thanks in advance

1 Answer 1

2

this is happening because you're doing the array_unique call on each row!

You're doing this:

while($row = $db->sql_fetchrow($result)){
    $dl_tags_id = $row['tags'];
    $dl_tags_id_ex = explode(" ",$dl_tags_id)   ;
    $dl_tags_id = array_unique($dl_tags_id_ex);
    // rest of code...
}

when really, you want to do this:

$dl_tags_all = '';
while($row = $db->sql_fetchrow($result)){
    $dl_tags_all .= ' '.$row['tags'];
}
$dl_tags_id_ex = explode(" ",substr($dl_tags_all,1));
$dl_tags_id = array_unique($dl_tags_id_ex);
//rest of code....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.