【发布时间】:2017-08-06 11:33:57
【问题描述】:
如何遍历从 PHP 函数返回的数组 Object 以检索记录集的所有记录?
试图让这段代码返回一个包含所有行的数组
// @param group_id @returns result rows of all post from group with the corresponding ID
function getGroupPostItem($group_id){
$sql_query = mysql_query("SELECT * FROM posts WHERE gid = '$group_id'");
while( $rows = mysql_fetch_assoc($sql_query)) {
$record_set = array('gid' => $rows['gid'],
'pid' => $rows['pid'],
'post' => $rows['post'],
'filemap_id' => $rows['filemap_id']);
return $record_set;
}
}
尝试使用下面的代码打印数据库中与查询匹配的行中的所有记录,但它所做的只是打印一行。
$arr = getGroupPostItem('6');
echo $arr['post']. '<br/>' ;
【问题讨论】: