PHP Tag Cloud Making--the structure and query method of datasheet

Source: Internet
Author: User
Tags array count explode php code query split tagname
For example, if you need an article that contains a tagname with ID 1,2,3 in the tag table, that is, a label with ID 1,2,3,   adds the article with       $result =implode (",", $_ post[' TagID '); split the array of fetched checkboxes with commas $_post[' tagid '] for an array of check boxes for the foreground, the foreground HTML section code is: <input type= "checkbox" Name= " Tagid[] "value=" {$tag. ID} "id=" {$tag. ID} "><label for=" {$tag. ID} ">{$tag. tagname}</label>// Here is the thinkphp, the original writing the same way to store articles, only need to mood table in the tag= $result can.       Data has been saved, and then what we need to achieve is to click on 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 have to get the ID of the article, query the tag of the article,   use the split function   $taglist = explode (', ', $source ); $source is the tag value for the article, for example: Split tag= "1,2,3" into an array and then write in the foreground:   for ($index =0; $index <count ($taglist); $index + +) {               $tagsa = $tagdata->where (' id=%d ', $taglist [$index])->select ();             echo "<a id= ' tag ' href= ' location/tag/". $tagsa [0][' id ']. "' > ". ($tagsa [0][' tagname ']). " </a>    ";              } loop output Tagname,url tag table ID value, next only need to receive URL value in the place to write a fuzzy query SQL, the article table of the tag like%id%.       NOTE: The above query statements are all thinkphp syntax.   This can result in a problem with a fuzzy query, because for example: one of the tag fields in the article table may contain 1,5     another tag field may contain 10,23   If you query the tag like%1% will query out of the   The tag field is 1,5   and   tag field 10,23   two articles. Even if the like condition is%1,% or%,1,% is not good.   So here I write the PHP code in the foreground, with two nested for loops to solve, as follows:   Copy code $map [' tag '] = array (' Like ', '% '. TagID. ') %');            //dump ($selecttag [$i] [' ID ']) $arr _mood= $mood->where ($map)->select (); For ($a =0 $a <count ($arr _mood); $a + +) {                $source = $arr _mood[$a] [' Tag '];                 $taglist = explode (', ', $source);                                &NBSP;&NBSP ;                 for ($index =0 $index <count ($taglist); $index + +) {                                     &NB Sp     if (tagid== $taglist [$index]) {//When TagID is present in the tag field of the article, output.                             $arr _mood[$a [' titl E '];//This can be output with Echo to front                    }                                     }    &NB Sp                                 &NBSP ;        }

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.