PHP无限循环“,而”与类 [英] PHP Infinite Loop "While" with Class
本文介绍了PHP无限循环“,而”与类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了我的脚本没有类。 (框架)。现在我改变了主意,我想把我的脚本与类。我喜欢。但是我有一个问题..无限循环。
code> while($ fetch = $ db-> fetchObject($ db-> q(SELECT * FROM auction_house.items ORDER BY id DESC LIMIT。$ min_stuff。,。$ max_stuff。 )))
{
// etc
}
;
public function fetchObject($ queryRes)
{
$ this-> queryRes = $ queryRes ;
$ this-> record = mysql_fetch_object($ this-> queryRes);
return $ this-> record;
}
当我尝试while循环时,我在页面上进行无限循环。
我如何解决这个问题?
解决方案
它总是返回一个新的资源。
尝试分开查询和循环:
$ res = $ db-> q(SELECT * FROM auction_house.items ORDER BY id DESC LIMIT。$ min_stuff。,。$ max_stuff。);
pre>
while($ fetch = $ db-> fetchObject($ res))
{
// etc
}
I made my scripts without class. (framework). Now I have changed my mind & I wanna make my scripts with classes. I like it. But there I have a problem.. Infinite Loop While. I didn't take this problem before with without classes..
While Rule;
while ($fetch=$db->fetchObject($db->q("SELECT * FROM auction_house.items ORDER BY id DESC LIMIT ".$min_stuff.",".$max_stuff.""))) { // etc }
Class;
public function fetchObject($queryRes) { $this->queryRes = $queryRes; $this->record = mysql_fetch_object($this->queryRes); return $this->record; }
When I try to while loop, I am taking infinite loop on page. How can I solve this problem?
解决方案You executing query in each iteration. It always returns a new resource.
Try to separate query and cycle:
$res = $db->q("SELECT * FROM auction_house.items ORDER BY id DESC LIMIT ".$min_stuff.",".$max_stuff.""); while ($fetch=$db->fetchObject($res)) { // etc }
这篇关于PHP无限循环“,而”与类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文