Posted By

_Undefined on 06/12/08


Tagged

tags frequency


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

JustinCrossman


Tags based on frequency from a 'tags' field.


 / Published in: PHP
 

URL: http://underscoreundefined.co.cc/

Simple tag links from a database with tags stored in a field as 'tag,tag,tag,tag'.

  1. <?php
  2.  
  3. //MySQL query for tags.
  4. $tag_limit = 20;
  5. $mysql_tags = "SELECT tags FROM entries LIMIT $tag_limit";
  6. $mysql_qtags = mysql_query($mysql_tags) or die(mysql_error());
  7.  
  8. $tags = array();
  9.  
  10. while ($row = mysql_fetch_array($mysql_qtags)) {
  11. $row_tag_array = split(",", $row[0]);
  12. foreach ($row_tag_array as $newtag) {
  13. if (array_key_exists($newtag, $tags)) {
  14. if ($tags[$newtag] < 200) {
  15. $tags[$newtag] = $tags[$newtag] + 20;
  16. }
  17. }
  18. else {
  19. $tags[$newtag] = 100;
  20. }
  21. }
  22. }
  23.  
  24. foreach ($tags as $tag => $size) {
  25. echo "<a style=\"font-size: $size%;\" href=\"?t=$tag\">$tag</a> "; }
  26. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: JustinCrossman on June 14, 2008

Posted By: JustinCrossman on June 14, 2008

You need to login to post a comment.