我希望能够做到这样的事情:
function x(){
....blablabla..
return mysql_fetch_object($result);
}
$entries = x();
foreach($entries as $entry){
echo "$entry->member_1";
}
当我这样做时,它给了我0结果并且在屏幕上没有打印任何内容。我已经看过while循环解决方案太多次了,我想知道是否有办法使用for循环来做到这一点? THX
答案 0 :(得分:2)
你要么:
function x(){
....blablabla..
$return = array();
while($object = mysql_fetch_object($result)) $return[] = $object;
return $return;
}
$entries = x();
foreach($entries as $entry){
echo $entry->member_1;
}
或者:
function x(){
....blablabla..
return mysql_fetch_object($result);
}
$entries = x();
foreach(get_object_vars($entries) as $entry){
echo $entry->member_1;
}
我怀疑第一个。
答案 1 :(得分:1)
喜欢这个吗?
$result = mysql_query(..);
for (;$row = mysql_fetch_object($result);) {
echo $row->member_1;
}