Solve the problem that no data is found in mysqlFIND_IN_SET.

Source: Internet
Author: User
The selectMsg function can be output, but it won't work in the following cities. check whether it is a problem such as the table name. the field is also utf8, and the query can also be solved. After connecting to the database, add the following code {code ...}


$ Con = mysql_connect ("localhost", "root", "root"); // $ dbname = "weixin"; function selectMsg ($ str) {$ rows = array (); $ msgArr = array (); $ like = array (); $ arr = array (); $ SQL = "SELECT * FROM weixin. weixin_msg WHERE FIND_IN_SET ('". $ str. "', Title)"; $ result = mysql_query ($ SQL); while ($ rows = mysql_fetch_array ($ result, MYSQL_ASSOC) {$ msgArr [] = $ rows ;} if (! Empty ($ msgArr) {return $ msgArr;} else {$ sqlstr = "SELECT * FROM weixin. weixin_msg WHERE Title LIKE '% ". $ str. "% 'order by id desc"; $ like = mysql_query ($ sqlstr); while ($ arr = mysql_fetch_array ($ like, MYSQL_ASSOC )) {$ msgArr [] = $ arr;} return $ msgArr;} function cityName ($ keyword) {$ SQL = "SELECT * FROM weixin. weixin_cityname WHERE FIND_IN_SET ('". $ keyword. "', CityNameCn)"; $ result = mysql_fetch_array (mysql_query ($ SQL), MYSQL_ASSOC); print_r ($ result);} cityName ("Beijing "); $ res = selectMsg ("123"); echo"
";print_r($res);

The selectMsg function can be output,
However, the following cities won't work. Check whether the table name is a problem or not. The field is also utf8.

This query can also be performed.

Solution: add the following code after connecting to the database

Header ("Content-Type: text/html; charset = UTF-8"); // connect to the database $ con = mysql_connect ("localhost", "root", "root "); mysql_query ("set character set 'utf8'"); // read database mysql_query ("set names 'utf8'"); // write Database

One answer

Run the SQL command directly in the database.

Similar

Select * from city where FIND_IN_SET (city_name, '2013 ');

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.