For a PHP paging program, the following error occurs: phpcode=de_once (conn. php); if (isset ($ _ GET [pclass]) {$ p_pclass];} else {$ p _ ;}$ respagemysql_query (& quot; SELECTCOUNT (*) a php paging program reports an error
This is a paging program:
PHP code
Include_once ('Conn. php '); if (isset ($ _ GET ['pclass']) {$ p_class =$ _ GET ['pclass '];} else {$ p_class = '';} $ respage = mysql_query (" select count (*) FROM product where p_class = '$ p_class ';"); // $ num is the total number of qualified records in the data table while ($ row = mysql_fetch_assoc ($ respage) {$ num = $ row [0]; // This row reports an error: notice: Undefined offset: 0 in D: \ setup \ xampp \ htdocs \ products \ showclass. php on line 88} $ recordnum = 40; // how many records are displayed on each page, $ pages = ceil ($ num/$ recordnum ); // total number of pages if (@ $ _ GET ["page"]) // Obtain the parameter page in the url {// $ pre and $ next are the values of the connection parameter page in the previous and next pages. // if the parameter in the url is 1, set the current page to the previous one, $ pre as one, and $ next as 2 if ($ _ GET ["page"] = 1) {$ current = 1; // the current page $ pre = 1; // $ pre is the previous page $ next = 2; // $ next is the next page} else {$ current = $ _ GET ["page"]; $ pre = $ current-1; $ next = $ current + 1 ;} // if the parameter in the url is not one (not the first page), set the value of the current page to the parameter obtained in the url, $ pre is the current page minus 1, $ next is added with 1} else {$ current = 1; $ pre = '1'; $ next = 2;} // if there is no parameter page in the url, set the current page to 1, $ pre = 1, $ next = 2 $ now = ($ current-1) * $ recordnum; $ echopage ="
"; $ Echopage. ="
". $ Pages." page | "; $ Echopage. ="
Page 1 |
Last page | "; // Error: Notice: Undefined index: HP_SELF in D :\setup \ xampp \ htdocs \ products \ showclass. php on line 120 $ echopage. ="
Previous Page and Next page | "; // Error: Notice: Undefined index: HP_SELF in D :\setup \ xampp \ htdocs \ products \ showclass. php on line 120 $ echopage. ="
To\ N "; for ($ I = 1; $ I <= $ pages; $ I ++) {if ($ I = $ current) $ echopage. ="$ I\ N "; else $ echopage. ="$ I\ N ";}$ echopage. ="Page | "; $ Echopage. ="
";
The following is the code for paging:
PHP code
===== Error reported on the WEB:
Notice: Undefined offset: 0 in D: \ setup \ xampp \ htdocs \ products \ showclass. php on line 88
Notice: Undefined index: HP_SELF in D: \ setup \ xampp \ htdocs \ products \ showclass. php on line 120
Notice: Undefined index: HP_SELF in D: \ setup \ xampp \ htdocs \ products \ showclass. php on line 120
Notice: Undefined index: HP_SELF in D: \ setup \ xampp \ htdocs \ products \ showclass. php on line 121
------ Solution --------------------
$ Num = $ row [0]; // This row returns an error
Because mysql_fetch_assoc returns an associated array with no subscript
Change to mysql_fetch_array.
HP_SELF should be PHP_SELF