There are 4 tables used for storing tags:
tagovi, tagovi_vijesti, tagovi_blogovi, tagovi_dogadjanja
Structure od table tagovi
:
id - name
Structure of table tagovi_vijesti
:
id - vijesti_id - tag_id
The same is for other two tables.
On main page I display tags from all three tables this way:
$sql = "SELECT
T.id AS id, T.name AS tag,
TV.id AS tag_vijest_id, TD.id AS tag_dogadjanje_id, TB.id AS tag_blog_id,
COUNT(*) ponavljanje
FROM tagovi AS T
LEFT JOIN tagovi_vijesti AS TV ON T.id = TV.tag_id
LEFT JOIN tagovi_dogadjanja AS TD ON T.id = TD.tag_id
LEFT JOIN tagovi_blogovi AS TB ON T.id = TB.tag_id
WHERE TV.id IS NOT NULL
GROUP BY id
ORDER BY id DESC
LIMIT 35";
$sql_result = mysql_query($sql,$connect)
or die("Upit nije izvrsen");
while ($row = mysql_fetch_array($sql_result)){
$tag_id = $row["id"];
$tag_url = $row["tag"];
$tag = preg_replace('/-/', ' ', $tag_url);
$tag_ponavljanje = $row["ponavljanje"];
if($tag_ponavljanje >= 10 && $tag_ponavljanje < 20) $fontSize = "14px";
elseif($tag_ponavljanje >= 20 && $tag_ponavljanje < 30) $fontSize = "16px";
elseif($tag_ponavljanje >= 30 && $tag_ponavljanje < 40) $fontSize = "18px";
elseif($tag_ponavljanje >= 40 && $tag_ponavljanje < 60) $fontSize = "20px";
elseif($tag_ponavljanje >= 60) $fontSize = "24px";
else $fontSize = "12px";
echo " <a href = \"$ispisi_link/tag/$tag_url\" style=\"font-size: $fontSize;\">$tag</a> ";
}
But I don't think that this is the perfect way to do it because tags are sorted by id and then all those old tags will never be displayed again because results are sorted by id. What kind of display (query) do you use? What would you advise me about displaying tags? Is it better to sort them by number of repeating of each tag (in my table repeating is called "ponavljanje")? If I use this way then I'm bit afraid that there will be tags that will be repeated in most of content and new one will never be displayed on main page. Or should I maybe use two queries, one for new tags and one for those who are mostly used?
Thanks, Ile