0

当前输出为:3个数组

Array ( [pf_id] => 5 [pf_title] => Gender [pf_icon] => [pf_key] => gender )
Array ( [pf_id] => 6 [pf_title] => Location [pf_icon] => [pf_key] => location )
Array ( [pf_id] => 7 [pf_title] => Interests [pf_icon] => [pf_key] => interests )

结果必须是这样的: 1 个数组,包括每个 pf_id 的 1 个子数组

Array (
 5 => array ([pf_title] => Gender [pf_icon] => [pf_key] => gender)
 6 => array ([pf_title] => Location [pf_icon] => [pf_key] => location)
 7 => array ([pf_title] => Interests [pf_icon] => [pf_key] => interests)
)

获取数据的代码:

        $cfields = array();
        $this->DB->build( array(
            'select' => 'pf_d.pf_id, pf_d.pf_title, pf_d.pf_icon, pf_d.pf_key',
            'from' => array( 'pfields_data' => 'pf_d' ),
            'where' => 'pf_d.pf_id = 5 or pf_d.pf_id = 6 or pf_d.pf_id = 7',
        ) );
        // if ($this->settings['b_multiplayer_f_id'] && in_array( $this->request['f'], explode(',', $this->settings['b_multiplayer_f_id'] ) ) ) {
            print $this->DB->fetchSqlString();
        // }

        $this->DB->execute();
        while ( $row = $this->DB->fetch() ) {
// array correction starts please help!!
#                       $extract = array();
#                       $extract = implode/explode??
#           $extract[] = $row['pf_id'].' => '.array( 'pf_title' => $row['pf_title'], 'pf_icon' => $row['pf_icon'], 'pf_key' => $row['pf_key']);
// array correction finish
            $cfields[] = $extract;
            print_r($row);
        }

我正在使用 invisionpower 板(我是客户,但不需要他们的回应......来解决)

以及如何将数据数组(n => array())提取到模板中?示例代码:

<foreach loop="$cfields as $key=>$value">
{$value[pf_title]} => {$this->memberData['field_'.$key]}
</foreach>

是正确的?

4

1 回答 1

0

我已经解决了...我将 while() 编辑为

while ( $row = $this->DB->fetch() ) {
    $b_array = array_slice($row, 1);
    $cfields[ $row['pf_id'] ] = $b_array;
}

结果

Array
(
    [5] => Array
        (
            [pf_title] => Gender
            [pf_icon] => 
            [pf_key] => gender
        )

    [6] => Array
        (
            [pf_title] => Location
            [pf_icon] => 
            [pf_key] => location
        )

    [7] => Array
        (
            [pf_title] => Interests
            [pf_icon] => 
            [pf_key] => interests
        )

)
于 2013-08-31T23:21:20.567 回答