PHP Tag Cloud Implementation code

Source: Internet
Author: User
In the database, there is a "tag" field in the table that holds the article, which is used to store the label. The tags are separated by ",". such as "Php,vb, essays."
The following implementation code, the label from the database to search out, and format processing, so that it appears as the number of times based on the display of different sizes of text connections.
The details of which do not explain!
The implementation code for the label cloud with concept Chen, method stupid, and low efficiency is as follows:
Copy the code code as follows:
/**
* Wniaoblog Tag Template Showtag
*
* @package Wniaoblog
*
* @subpackage Tag
*/
Connect the database
Include ('.. /include/config.php ');
/**
* Counttag ()-Statistics labels appear the Number,and the data to being stored in the both array
*
* Gettag ()-Access the Tag ' s Labels from the database
*/
function Counttag ($String) {
$TagString = $String;
echo $TagString. "
";
$Tags = Explode (",", $TagString);
$n = 1;
$i = 0;
$Continue = TRUE;
echo $Tags [1]. "
";
In case No-label ' s article
while ($Tags [$n] or $Tags [+ + $n] or $Tags [+ + $n]) {
$EachTag = $Tags [$n + +];
echo $EachTag. "
";
$Continue = TRUE;
for ($i =0; $Continue; $i + +) {
if ($EachTagStr [$i][0]) {
if ($EachTagStr [$i][0] = = $EachTag) {
$EACHTAGSTR [$i][1]++;
$Continue = FALSE;
}
else {
if ($EachTagStr [$i +1][0]) $Continue = TRUE;
else {
$EACHTAGSTR [$i +1][0] = $EachTag;
$EACHTAGSTR [$i +1][1] = 1;
$Continue = FALSE;
}
}
} else {//initialize the array $EachTagStr []
$EACHTAGSTR [$i][0] = $EachTag;
$EACHTAGSTR [$i][1] = 1;
$Continue = FALSE;
}
}
}
return $EachTagStr;
}
function Showtag ($Row, $ablink) {
$i = 0;
while ($Row [$i][0]) {
$EachTag = $Row [$i][0];
$EachCount = $Row [$i][1];
$Size = SetSize ($EachCount);
echo "< a style= ' color:blue; Font-size: ". $Size." ' onmouseover=this.style.color= ' #900000 ' onmouseout=this.style.color= ' BLUE ' href= ' http://www.php1.cn/' > $i + +;
}
}
function Gettag () {
$QuerySet = mysql_query ("SELECT * from article");
while ($Row = Mysql_fetch_array ($QuerySet)) {
$Tag = $Row [' Tag '];
$TagString = $TagString. ",". $Tag;
}
return $TagString;
}
function SetSize ($Size) {
$Size + = 10;
if ($Size > 30)
$Size = 30;
return $Size;
}
Go
echo "
";
echo "Tag Cloud";
$String = Gettag ();
$Row = Counttag ($String);
Showtag ($Row, $ablink);
echo "
";
?>

ok,done!
  • 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.