Fatalerror: Calltoamemberfunctionfpage () onanon-object

Source: Internet
Author: User
Fatalerror: Calltoamemberfunctionfpage () onanon-object smarty I call the paging function. page. class. php has been called on the page and has been instantiated. the specific statement is as follows:
/* Product list */
Function get_product_list ($ cat_id)
{
If ($ cat_id)
{
$ Num = 6;
$ Where = "where classid = '$ cat_id' and shenhe = 1 ";
$ Sql1 = $ GLOBALS ['DB']-> query ("select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "");
$ Total = $ GLOBALS ['DB']-> num_rows ($ sql1 );
}
Else
{
$ Num = 6;
$ Where = "where shenhe = 1 ";
$ Sql2 = $ GLOBALS ['DB']-> query ("select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "");
$ Total = $ GLOBALS ['DB']-> num_rows ($ sql2 );
}
$ Page = new page ($ total, $ num );
// Echo $ total;
// Exit ();
$ SQL = "select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "order by addtime desc {$ page-> limit }";
While ($ row = $ GLOBALS ['DB']-> fetch_array ($ SQL ))
{
$ Url = $ GLOBALS ['DB']-> rewrite_url ('cpxx _ xx', $ row ['produd d']);
$ Product_list [] = array (
"Id" => $ row ['produtid'],
"Title" => $ row ['title'],
"Image" => $ row ['image']
);
}
Return $ product_list;
}
/* Initialize data */
$ Smarty-> assign ('Ur _ here ', $ db-> ur_here ('product _ class', $ cat_id ));
$ Smarty-> assign ('product _ category ', $ db-> get_product_category (''); // The left-side category list of the product
$ Smarty-> assign ('product _ list', get_product_list ($ cat_id); // product list
$ Smarty-> assign ('page _ Nav', $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 ))); // This error occurs on the product page. I am very grateful to anyone who can help me solve this problem ~!


Reply to discussion (solution)

$ Page = new page ($ total, $ num );
Check whether the generated object is a valid object. There are also the total and num values.

$ Page = new page ($ total, $ num );
Check whether the generated object is a valid object. There are also the total and num values.


Page Object ([total: private] => 5 [listRows: private] => 6 [limit: private] => Limit 0, 6 [uri: private] =>/zangbaoshengwu/cpxx. php? [PageNum: private] => 1 [config: private] => Array ([header] => records [prev] => Previous Page [next] => next Page [first] => first Page [last] => last page) [listNum: private] => 8 [page] => 1)
$ Total, $ num all have values

$ Page is initialized in the function. That is, it is a local variable. of course, you cannot use it outside the function.

$ Page is initialized in the function. That is, it is a local variable. of course, you cannot use it outside the function.


What should I do? How do I write in a function?

Return as the return value of the function, for example:
Return $ product_list;
Change to return array (
'List' => $ product_list,
'Fpage' => $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 )),
)
.

Return as the return value of the function, for example:
Return $ product_list;
Change to return array (
'List' => $ product_list,
'Fpage' => $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 )),
)
.


I don't know how to implement it, but how can I write smarty?
$ Smarty-> assign ('product _ list', get_product_list ($ cat_id); // product list
$ Smarty-> assign ('page _ Nav', $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8); // product page
This is where.

Change the function return value to #5.

$ Smarty-> assign ('product _ list', get_product_list ($ cat_id); // product list
$ Smarty-> assign ('page _ Nav', $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 )));
Changed:
$ Ar = get_product_list ($ cat_id );
$ Smarty-> assign ('product _ list', $ ar ['list']); // product list
$ Smarty-> assign ('page _ Nav', $ ar ['fpage']);

Change the function return value to #5.

$ Smarty-> assign ('product _ list', get_product_list ($ cat_id); // product list
$ Smarty-> assign ('page _ Nav', $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 )));
Changed:
$ Ar = get_product_list ($ cat_id );
$ Smarty-> assign ('product _ list', $ ar ['list']); // product list
$ Smarty-> assign ('page _ Nav', $ ar ['fpage']);


How to print out the array value list is empty:
Array ([list] => [fpage] => 1. a total of five records are displayed on each page. 1-5 records are displayed on 1/1 pages)
The following is a complete program:
/* Product list */
Function get_product_list ($ cat_id)
{
If ($ cat_id)
{
$ Num = 6;
$ Where = "where classid = $ cat_id and shenhe = 1 ";
$ Sql1 = $ GLOBALS ['DB']-> query ("select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "");
$ Total = $ GLOBALS ['DB']-> num_rows ($ sql1 );
}
Else
{
$ Num = 6;
$ Where = "where shenhe = 1 ";
$ Sql2 = $ GLOBALS ['DB']-> query ("select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "");
$ Total = $ GLOBALS ['DB']-> num_rows ($ sql2 );
}
$ Page = new page ($ total, $ num );
$ SQL = "select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "order by addtime desc {$ page-> limit }";
While ($ row = $ GLOBALS ['DB']-> fetch_array ($ SQL ))
{
$ Url = $ GLOBALS ['DB']-> rewrite_url ('cpxx _ xx', $ row ['produd d']);
$ Product_list [] = array (
"Id" => $ row ['produtid'],
"Title" => $ row ['title'],
"Image" => $ row ['image']
);
}
// Return $ product_list;
Return array (
'List' => $ product_list,
'Fpage' => $ page-> fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8 ))
);
}

/* Initialize data */
$ Smarty-> assign ('Ur _ here ', $ db-> ur_here ('product _ class', $ cat_id ));
$ Smarty-> assign ('product _ category ', $ db-> get_product_category (''); // The left-side category list of the product
$ Ar = get_product_list ($ cat_id );

Print_r ($ ar );

$ Smarty-> assign ('product _ list', $ ar ['list']); // product list
$ Smarty-> assign ('page _ Nav', $ ar ['fpage']); // product page
Why can't I find it?

Function get_product_list ($ cat_id)
{
Global $ page; // add this sentence
If ($ cat_id)
..........

Other changes are not required

Sorry, I wrote the SQL query statement incorrectly:
$ SQL = "select * from ". $ GLOBALS ['DB']-> table ('product '). $ where. "order by addtime desc {$ page-> limit }";
While ($ row = $ GLOBALS ['DB']-> fetch_array ($ SQL ))
$ GLOBALS ['DB']-query () is missing here ();

Sorry, there are only so many points, but there are only a small number of points, so you have to wait for a while ~

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.