PHP implements a piece of code for the tag cloud

Source: Internet
Author: User
  1. /**
  2. * Wniaoblog Tag Template Showtag
  3. *
  4. * @package Wniaoblog
  5. *
  6. * @subpackage Tag
  7. */
  8. Connect the database
  9. Include ('.. /include/config.php ');
  10. /**
  11. * Counttag ()-Statistics labels appear the Number,and the data to being stored in the both array
  12. *
  13. * Gettag ()-Access the Tag ' s Labels from the database
  14. */
  15. function Counttag ($String) {
  16. $TagString = $String;
  17. echo $TagString. "
  18. ";
  19. $Tags = Explode (",", $TagString);
  20. $n = 1;
  21. $i = 0;
  22. $Continue = TRUE;
  23. echo $Tags [1]. "
  24. ";
  25. In case No-label ' s article
  26. while ($Tags [$n] or $Tags [+ + $n] or $Tags [+ + $n]) {
  27. $EachTag = $Tags [$n + +];
  28. echo $EachTag. "
  29. ";
  30. $Continue = TRUE;
  31. for ($i =0; $Continue; $i + +) {
  32. if ($EachTagStr [$i][0]) {
  33. if ($EachTagStr [$i][0] = = $EachTag) {
  34. $EACHTAGSTR [$i][1]++;
  35. $Continue = FALSE;
  36. }
  37. else {
  38. if ($EachTagStr [$i +1][0]) $Continue = TRUE;
  39. else {
  40. $EACHTAGSTR [$i +1][0] = $EachTag;
  41. $EACHTAGSTR [$i +1][1] = 1;
  42. $Continue = FALSE;
  43. }
  44. }
  45. } else {//initialize the array $EachTagStr []
  46. $EACHTAGSTR [$i][0] = $EachTag;
  47. $EACHTAGSTR [$i][1] = 1;
  48. $Continue = FALSE;
  49. }
  50. }
  51. }
  52. return $EachTagStr;
  53. }
  54. function Showtag ($Row, $ablink) {
  55. $i = 0;
  56. while ($Row [$i][0]) {
  57. $EachTag = $Row [$i][0];
  58. $EachCount = $Row [$i][1];
  59. $Size = SetSize ($EachCount);
  60. echo "< a style= ' color:blue; Font-size: ". $Size." ' onmouseover=this.style.color= ' #900000 ' onmouseout=this.style.color= ' BLUE ' href= '. $ablink. " Tag?tag= ". $EachTag." ' target= ' _self ' > '. $EachTag. ' (". $EachCount.") "." ";
  61. $i + +;
  62. }
  63. }
  64. function Gettag () {
  65. $QuerySet = mysql_query ("SELECT * from article");
  66. while ($Row = Mysql_fetch_array ($QuerySet)) {
  67. $Tag = $Row [' Tag '];
  68. $TagString = $TagString. ",". $Tag;
  69. }
  70. return $TagString;
  71. }
  72. function SetSize ($Size) {
  73. $Size + = 10;
  74. if ($Size > 30)
  75. $Size = 30;
  76. return $Size;
  77. }
  78. Go
  79. echo "
  80. ";
  81. echo "Tag Cloud";
  82. $String = Gettag ();
  83. $Row = Counttag ($String);
  84. Showtag ($Row, $ablink);
  85. echo "
  86. ";
  87. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.