Tag Cloud is a collection of related articles. we can collect many articles, and many seo-optimized users will add some seo tags to the website, let's take a look at the complete php Tag Cloud production process. Tag Cloud is a collection of related articles. we can collect many articles, and many seo-optimized users will add some seo tags to the website, let's take a look at the complete php Tag Cloud production process.
Script ec (2); script
1. Data Table Structure:
Create two data tables with the following structure:
Tag table:
Article mood table:
The tag field in the mood table is the id field of the tag table + "," + id field of the tag table,
2. query method:
For example, if you want an article to contain the tagname of 1, 2, 3 in the tag table, that is, the tagname of id 1, 2, 3,
Use
$ Result = implode (",", $ _ POST ['tagid']); // use commas to separate the obtained checkbox array.
$ _ POST ['tagid'] is an array for obtaining the front-end check boxes. The front-end html code is:
{$ Tag. tagname}// Here is the thinkphp method. The native method is similar.
In this way, only the tag = $ result in the mood table is required to store the article.
After the data is saved, we need to click the corresponding tag to query all the articles that contain the tag.
If we need to display all the tags contained in an article, we need to first obtain the id of the article and query the tag of the article,
Split Functions
$ Taglist = explode (',', $ source); // $ source is the tag value of the article. For example, divide tag = "1, 2, 3" into an array.
Then you can write in the foreground as follows:
For ($ index = 0; $ index
$ Tagsa = $ tagdata-> where ('Id = % d', $ taglist [$ index])-> select ();
Echo "". ($ tagsa [0] ['tagname']). "";
}
The tagname is output cyclically, And the url transmits the id value of the tag table. Next, you only need to write a fuzzy query SQL statement where the url value is received. The tag like % id % of the document table.
Note: The preceding query statements are the thinkphp syntax.
In this case, fuzzy query may cause a problem, because, for example, one tag field in the Document Table may contain 1, 5, and the other tag field may contain
If you query tag like % 1%, two articles with the tag field and the tag field are displayed. Even if the like condition is % 1, %, %, 1, %, it will not work.
So here I write php code at the front end and solve it with two nested for loops:
$ Map ['tag'] = array ('like', '%'. tagid. '% ');
// Dump ($ selecttag [$ I] ['id']); $ arr_mood = $ mood-> where ($ map)-> select (); for ($ a = 0; $
$ Source = $ arr_mood [$ a] ['tag'];
$ Taglist = explode (',', $ source );
For ($ index = 0; $ index < p>
<>
If (tagid = $ taglist [$ index]) {// when the uploaded tagid exists in the tag field of the article, it is output.
Dump ($ arr_mood [$ a] ['title']); // echo can be used to output to the foreground.
}
}
}
As a beginner in php, the code is rough. Sorry.