Fatal error: Call to a member function fpage() on a non-object $page=new page($total,$num);检查生成的对象是否是有效对象。还有total和num的值。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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] => 个记录 [prev] => 上一页 [next] => 下一页 [first] => 首 页 [last] => 尾 页 ) [listNum:private] => 8 [page] => 1 ) $total,$num都是有值的 $page 是在函数中初始化的。也就是他是一个局部变量,当然你不能在函数外使用。 作为函数的返回值返回,例如: return $product_list;改为 return array( 'list'=>$product_list, 'fpage'=>$page->fpage(array(3,4,5,6,7,0,1,2,8)),)。 理解这个意思,但是不太懂怎么去实现,而smarty我怎么写?$smarty->assign('product_list',get_product_list($cat_id)); //产品列表$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8))); //产品分页就是这里。 函数返回值改成#5那样写。$smarty->assign('product_list',get_product_list($cat_id)); //产品列表$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8))); 改为:$ar = get_product_list($cat_id);$smarty->assign('product_list',$ar['list']); //产品列表$smarty->assign('page_nav',$ar['fpage']); 怎么打印出的数组值list是空的:Array ( [list] => [fpage] => 1 共有5个记录 每页显示5条,本页1-5条 1/1页 ) 下面是完整的程序:/*产品列表*/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['productid']); $product_list[] = array( "id" => $row['productid'], "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)));}/*初始化数据*/$smarty->assign('ur_here',$db->ur_here('product_class',$cat_id));$smarty->assign('product_category',$db->get_product_category('')); //产品展示左侧分类列表$ar = get_product_list($cat_id);print_r($ar);$smarty->assign('product_list',$ar['list']); //产品列表$smarty->assign('page_nav',$ar['fpage']);//产品分页实在找不到哪错了呢? function get_product_list($cat_id){ global $page; //加上这句 if($cat_id)..........其他无需改动 对不起啦,是我自己把SQL查询语句写错了:$sql="select * from ".$GLOBALS['db']->table('product').$where."order by addtime desc {$page->limit}"; while($row=$GLOBALS['db']->fetch_array($sql))这里少了$GLOBALS['db']-query(); 求助3 关于MYSQL的连接数和连接时间的问题 请教高手一个问题,谈谈如何判断一个数据插入到mysql当中是否成功了,写出你的php代码。 求助:文章内容页关键字替换 诚聘网站PHP工程师 请问怎么使GD2同时支持JPEG和GIF? echo array_intersect的问题 smarty是不是自动缓存模板? <input type=button ...> 能不能設置這個東西的長度啊??? 求PHP和ASP连接SQL SERVER的程序 discuz x3 + cas 整合问题 php里怎么把循环数组赋值给字符串变量
$total,$num都是有值的
return $product_list;
改为 return array(
'list'=>$product_list,
'fpage'=>$page->fpage(array(3,4,5,6,7,0,1,2,8)),
)
。
$smarty->assign('product_list',get_product_list($cat_id)); //产品列表
$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8))); //产品分页
就是这里。
$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8)));
改为:
$ar = get_product_list($cat_id);
$smarty->assign('product_list',$ar['list']); //产品列表
$smarty->assign('page_nav',$ar['fpage']);
Array ( [list] => [fpage] => 1 共有5个记录 每页显示5条,本页1-5条 1/1页 )
下面是完整的程序:
/*产品列表*/
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['productid']);
$product_list[] = array(
"id" => $row['productid'],
"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))
);
}/*初始化数据*/
$smarty->assign('ur_here',$db->ur_here('product_class',$cat_id));
$smarty->assign('product_category',$db->get_product_category('')); //产品展示左侧分类列表
$ar = get_product_list($cat_id);print_r($ar);$smarty->assign('product_list',$ar['list']); //产品列表
$smarty->assign('page_nav',$ar['fpage']);//产品分页
实在找不到哪错了呢?
{
global $page; //加上这句
if($cat_id)
..........其他无需改动
$sql="select * from ".$GLOBALS['db']->table('product').$where."order by addtime desc {$page->limit}";
while($row=$GLOBALS['db']->fetch_array($sql))
这里少了$GLOBALS['db']-query();