Ask a php question about calling the database output

Source: Internet
Author: User
I want to teach you how to use php to call the database output. The purpose is to make a selection range, then query the database through these ranges, and format the output results. However, if the output results are correct, I am confused for a long time. The following is the error section. code PHPcodemysql_query ('setnamesgbk ', $ conn); mysql_select asks for a php call to the database output
The purpose is to make a selection range, query the database through these ranges, and format the output results.

However, if the output is achieved, the problem occurs. it is hard to understand for a long time.
The following is the error code
PHP code
  Mysql_query ('set names gbk', $ conn); mysql_select_db ('HTC ', $ conn); $ count = 'SELECT count (*) from phone '; $ query = mysql_query ($ count, $ conn); // total records $ recordcount = mysql_result ($ query,); // multiple entries per page $ pagesize = 5; // total page number $ pagecount = ceil ($ recordcount/$ pagesize); // Current page $ currpage = 1; if ($ _ GET) {$ currpage = (int) $ _ GET ['P'] ;}$ currpage = $ currpage <1? 1: $ currpage; $ currpage = $ currpage> $ pagecount? $ Pagecount: $ currpage; $ start = ($ currpage-1) * $ pagesize; $ SQL = "select * from phone order by id desc limit $ start, $ pagesize "; $ result = mysql_query ($ SQL, $ conn); while ($ row = mysql_fetch_array ($ result) {foreach ($ row as $ k => $ va) {// echo'
'; // Print_r ($ row); echo ""; echo "". ""; echo"

$ Va [1]


$ Va [4], $ va [5]
$ Va [6], $ va [7]
$ Va [8], $ va [9]

$ Va [10]

"; Echo" price: $ va [3]
"; Echo" "; // echo'
';}} Echo 'homepage'; echo 'next page'; echo 'previous page'; echo "last page "; echo "[{$ currpage}/{$ pagecount}] [{$ recordcount} records in total, {$ pagesize} records per page]";?> > Nth Page

The error message is many rows.
However, it is basically a prompt


Notice: Uninitialized string offset: 6 in D: \ Program Files \ Apache \ htdocs \ pro \ phone_zone.php on line 183

Notice: Uninitialized string offset: 7 in D: \ Program Files \ Apache \ htdocs \ pro \ phone_zone.php on line 183

Tutorial

------ Solution --------------------
While ($ row = mysql_fetch_array ($ result) {// mysql_fetch_array ($ result) returns a one-dimensional array
Foreach ($ row as $ k => $ va) {// so $ va is a single value data
// Echo'
';
// Print_r ($ row );

Echo "";
Echo ""."";
Echo"

$ Va [1]



$ Va [4], $ va [5]

$ Va [6], $ va [7]
// Therefore, $ va [6] and $ va [7] can only be a single character. if $ val is not that long, an error is returned.

I think your intention is

While ($ val = mysql_fetch_array ($ result )){
// Foreach ($ row as $ k => $ va ){

That is to say, $ va [6] and $ va [7] are the values of the 6 and 7 fields.
------ Solution --------------------
Remove the layer loop of foreach.
While ($ va = mysql_fetch_row ($ result )){
//...
}

As for your question in #2, I won't use regular expressions, so it won't help.
------ Solution --------------------

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.