Question

current output is: 3 array

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 )

the result must be this: 1 array including 1 subarray for each pf_id

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)
)

the code for to fetch data:

        $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);
        }

i am using invisionpower board (i am customer but it not require a their response... to solve)

and how I fetch data array( n => array()) into template? exemple code:

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

is correct?

Was it helpful?

Solution

i have solved... I edit while() into

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

result

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
        )

)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top