Table of Contents
PHP tag cloud production - data table structure and query method
Home Backend Development PHP Tutorial PHP tag cloud production - data table structure and query method_PHP tutorial

PHP tag cloud production - data table structure and query method_PHP tutorial

Jul 13, 2016 am 10:19 AM
data sheet Label structure

PHP tag cloud production - data table structure and query method

For example: If you need an article to contain tagnames with ids 1,2,3 in the tag table, that is, tags with ids 1,2,3,
then use
when adding an article
$result=implode(",", $_POST['tagid']);//Split the obtained checkbox array with commas
$_POST['tagid'] is an array to obtain the checkboxes in the frontend. The frontend html part code is:
//This is how thinkphp is written, the native way of writing is similar
When storing articles in this way, you only need tag=$result in the mood table.
The data has been saved. What we need to achieve next is to click on the corresponding tag to query all articles containing that tag.
If we need to display all the tags contained in an article, we must first obtain the id of the article and query the tag of the article,
Use split function
$taglist = explode(',',$source); //$source is the tag value of the article, for example: split tag="1,2,3" into an array
Then you can write like this in the front desk:
for($index=0;$index
$tagsa=$tagdata->where('id=%d',$taglist[$index])->select();
                    echo "".($tagsa[0]['tagname'] )."   " ;
      }
Loop to output the tagname, and the url passes the id value of the tag table. Next, you only need to write a fuzzy query sql where the url value is received, and the tag of the article table is like %id%.
Note: The above query statements are all thinkphp syntax.
There will be a problem when using fuzzy query like this, because for example: one of the tag fields in the article table may contain 1,5 and the other tag field may contain 10,23
If you query tag like %1%, you will find two articles with tag field 1,5 and tag field 10,23. Even if the like condition is %1,% or %,1,%, it will not work.
So my way of writing here is to write php code in the foreground and use two nested for loops to solve the problem, 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);
                                                       
                                                       
for($index=0;$index
                                                                             
if (tagid == $ taglist [$ Index]) {// When the tagid that comes over exists in the tag field of the article, the output is output.
                                                                                                                                                                                                                                                             dump($arr_mood[$a]['title']);//Here you can use echo to output to the front desk
          }
                                                                             
        }  
                                                       
                                                       
      }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871180.htmlTechArticlephp tag cloud production - data table structure and query method. For example: if you need a tag table to be included in an article The tagname with id 1,2,3, that is, the tag with id 1,2,3, then add the text...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Data table compression technology in MySQL Data table compression technology in MySQL Jun 16, 2023 am 08:16 AM

MySQL is a common relational database that is a core component of many websites and applications. As the amount of data becomes larger and larger, how to optimize the performance of MySQL becomes particularly important. One of the key areas is the compression of data tables. In this article we will introduce the data table compression technology in MySQL. Compressed tables and non-compressed tables There are two types of data tables in MySQL: compressed tables and non-compressed tables. Uncompressed tables are MySQL's default table type, which use fixed-length row format to store data. This means data

What is the clock behind the TikTok label? How to tag Douyin account? What is the clock behind the TikTok label? How to tag Douyin account? Mar 24, 2024 pm 03:46 PM

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of &quot;What is the clock behind the Douyin label&quot;, hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

What are the syntax and structure characteristics of lambda expressions? What are the syntax and structure characteristics of lambda expressions? Apr 25, 2024 pm 01:12 PM

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? Mar 22, 2024 am 10:28 AM

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

In-depth analysis of the structure and purpose of the MySQL.proc table In-depth analysis of the structure and purpose of the MySQL.proc table Mar 15, 2024 pm 02:36 PM

The MySQL.proc table is a system table that stores stored procedure and function information in the MySQL database. By in-depth understanding of its structure and purpose, you can better understand the operating mechanism of stored procedures and functions in MySQL, and perform related management and optimization. The structure and purpose of the MySQL.proc table will be analyzed in detail below, and specific code examples will be provided. 1. The structure of the MySQL.proc table. The MySQL.proc table is a system table that stores the definitions and related information of all stored procedures and functions.

A closer look at the video element in HTML A closer look at the video element in HTML Feb 24, 2024 pm 08:18 PM

Detailed explanation of the video tag in HTML The video tag in HTML5 is a tag used to play videos on web pages. It can render videos using different formats, such as MP4, WebM, Ogg, and more. In this article, we will introduce the use of video tag in detail and provide specific code examples. Basic Structure The following is the basic structure of the video tag:

What is the origin of the basic structure and technology of the internet? What is the origin of the basic structure and technology of the internet? Dec 15, 2020 pm 04:48 PM

The basic structure and technology of the internet originated from ARPANET. ARPANET is a milestone in the development of computer network technology. Its research results have played an important role in promoting the development of network technology and laid the foundation for the formation of the Internet. Arpanet (Arpanet) was the world's first operational packet switching network developed by the U.S. Defense Advanced Research Projects Agency. It is the ancestor of the global Internet.

See all articles