0

问题是 $callback 的第一个维度永远不会超过第二个维度的长度。
例如,如果我添加一个其他字段,例如:
$callback[$counter]['field'] = $rec['filed'];
两个长度都将变为 6。我该如何解决这个问题?

public function returnAll(&$callback) {
    $callback = array();
    $counter  = 0;
    $this->db->query("SELECT * FROM `news` WHERE 1 ");
    $rec = $this->db->NextRecord();

    if (!($this->db->num_row() > 1))
        return false;

    while ( $rec ) {
        $callback[$counter]['title'] = $rec['title'];
        $callback[$counter]['text']  = $rec['text'];
        $callback[$counter]['type']  = $rec['type'];
        $callback[$counter]['abstract'] = $rec['abstract'];
        $callback[$counter]['news_date'] = $rec['news_date'];
        $rec = $this->db->NextRecord();

        $counter++;
    }

    return true;      
}
4

1 回答 1

4

在这种情况下,因为您的密钥是相同的,您可以这样做:

$callback = array();
while($rec = $this->db->NextRecord()){
     $callback[] = $rec;
}
于 2013-06-18T14:18:26.087 回答