TP5.0 How to use arrays to query MySQL when using functions

Source: Internet
Author: User

Today, when querying the data, a small problem is that when querying data with TP5.0, a function is needed find_in_set for the purpose of this function is to give an example first:
There is an article table with a Type field, which stores the article type, there are 1 headlines, 2 recommendations, 3 hotspots, 4 graphics and so on. Now there is an article that he is a headline, hot, or graphic, type in the format of 1,3,4 storage. So how do we use SQL to find 4 of all types of text in the type?? Then we need to use the Find_in_set function for more details on this function Portal: http://www.cnblogs.com/xiaoxi/p/5889486.html

Said so much below look at the examples in TP5 I know there are two ways

The first form of an array is an exp is an expression of TP

The Recommend_status field exists in the database in the form of the Find_in_set function.

1 $map []=[' exp ', ' Find_in_set (3,recommend_status) ']; 2 $map [' game_status '] = 1; 3 4 db::name (' Game ')->where ($map)->select ();

The second type is in string form

db::name (' Game ')->where ("Game_status=1 and Find_in_set (' 3 ', Recommend_status)")->select ();

Second, you can also use a string expression in the where condition when using other query methods

Db::name (' Game ')->where (' Recommend_status ', ' exp ', ' and Find_in_set (3,recommend_status) ')->select ();

such as children's shoes in the study TP5 encountered do not understand can leave a message below

This article for the author of the original article, reproduced without contact with me, but please specify from http://www.cnblogs.com/kzfbk/p/7728566.html

TP5.0 How to use arrays to query MySQL when using functions

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.