Garbled characters are displayed on the interface. how can this problem be solved?

Source: Internet
Author: User
The page displays garbled characters & nbsp; my query statement is: mysql_query (& quot; SETNAMESUTF8 & quot;); // if the number of elements in the array is 1, if (count ($ newstr) = 1) {$ SQL = & q

My query statement is:
Mysql_query ("set names UTF8 ");
// If the number of elements in the array is one, query by a single condition
If (count ($ newstr) = 1 ){
$ SQL = "select * from commodity where commodity_name like '% ". $ newstr [0]. "% 'or Sale_Address like' % ". $ newstr [0]. "% 'Order by id desc ";
}
Else {
// Merge query result sets
For ($ I = 0; $ I $ Sql0. = "commodity_name like '%". trim ($ newstr [$ I]). "%'". "or ";
}
For ($ j = 0; $ j $ Sql1. = "Sale_Address like '%". trim ($ newstr [$ j]). "%'". "or ";
}
$ Sql1 = substr ($ sql1, 0,-3); // remove the last "or"
$ SQL = "select * from commodity where". $ sql0. $ sql1. "order by id desc ";
}
Require_once ("common/db_mysql.class.php ");
$ DB = new DB_MySQL;
// Obtain the total number of records

$ DB-> query ($ SQL );
$ Row_count_sum = $ DB-> get_rows (); // number of rows recorded in the returned result set
// The number of records per page. you can use the default value or directly specify the value.
$ Row_per_page = 6;
// Total number of pages
$ Page_count = ceil ($ row_count_sum/$ row_per_page );
// Determine whether it is the first or last page
$ Is_first = (1 = $ page_num )? 1: 0;
$ Is_last = ($ page_num = $ page_count )? 1: 0;
// Query the start row position
$ Start_row = ($ page_num-1) * $ row_per_page;
// Add a limit clause for an SQL statement
$ SQL. = "limit $ start_row, $ row_per_page ";
// Execute the query
$ DB-> query ($ SQL );
$ Res = $ DB-> get_rows_array (); // An array composed of returned result set records
// Number of rows in the result set
$ Rows_count = count ($ res );

For ($ I = 0; $ I <$ rows_count; $ I ++ ){
$ Id = $ res [$ I] ['id']; // id
$ Title = $ res [$ I] ['commodity _ name']; // title
$ Content = $ res [$ I] ['sale _ address']; // content
Echo $ id. $ title. "**". $ content ."&&";
}


When I run normally, the result is: 62. How big is fengfeifei **? & 61ssssss ** ssss & 60, hahaha ** re-engineering & 59, hmm? ** hmm &&
But occasionally an exception occurs: 62 ??? **?? & 61ssssss ** ssss & 60 ??? **???? & 59 ??? **??? &&
I try to change the compatibility of the browser. sometimes it can restore to normal, and sometimes it is useless to change it. what is the situation? Can the code handle this situation?
(The above code has two user-defined functions. if you think it is necessary, I will post them again.) Thank you for your help.

------ Solution --------------------
PHP code
# Add header ("content-type: text/html; charset: UTF-8") at the beginning of the PHP page ");
------ Solution --------------------
What is the database code? What is the php file encoding? After unification, there is generally no problem.
------ Solution --------------------
Another possibility is that your editor has a problem! Did you change from gb2312 to UTF-8?

------ Solution --------------------
I have encountered, export, and import (another framework), all of which are ?????? And so on. if you add it again, it will be normal.

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.