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_db (htc, $ conn); $ countselectcount (*) ask a php to call 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 --------------------