On Jun 1, 2011, at 10:40 AM, Adam Preece wrote:

sorry i should of explained a little more in depth :-).

i am using smarty templating engine,

and it needs me to pass in an associative array.

only an id column and a the name column.

i know if i use a more specific query, but if i have the result set already could i build the array so it suits the template function?

this is the function details:

http://www.smarty.net/docsv2/en/language.function.html.options.tpl

and this is the array im currently fetching.

Array ( [0] => Array ( [id] => 2 [0] => 2 [name] => category 1 [1] => category 1 [main_nav] => true [2] => true ) [1] => Array ( [id] => 3 [0] => 3 [name] => category 2 [1] => category 2 [main_nav] => true [2] => true ) [2] => Array ( [id] => 4 [0] => 4 [name] => category 3 [1] => category 3 [main_nav] => true [2] => true ) [3] => Array ( [id] => 5 [0] => 5 [name] => category 4 [1] => category 4 [main_nav] => true [2] => true ) [4] => Array ( [id] => 6 [0] => 6 [name] => category 5 [1] => category 5 [main_nav] => true [2] => true ) [5] => Array ( [id] => 7 [0] => 7 [name] => category 6 [1] => category 6 [main_nav] => false [2] => false ) [6] => Array ( [id] => 8 [0] => 8 [name] => category 7 [1] => category 7 [main_nav] => false [2] => false ) [7] => Array ( [id] => 9 [0] => 9 [name] => category 8 [1] => category 8 [main_nav] => false [2] => false ) [8] => Array ( [id] => 10 [0] => 10 [name] => category 9 [1] => category 9 [main_nav] => false [2] => false ) [9] => Array ( [id] => 11 [0] => 11 [name] => category 10 [1] => category 10 [main_nav] => false [2] => false ) ) Array ( [0] => 2=>category 1 [1] => 3=>category 2 [2] => 4=>category 3 [3] => 5=>category 4 [4] => 6=>category 5 [5] => 7=>category 6 [6] => 8=>category 7 [7] => 9=>category 8 [8] => 10=>category 9 [9] => 11=>category 10

hope this makes sense?

This seems pretty straight-forward.

$options = array();

foreach ($rows as $row) {
        $options[]=list($row['id']=>$row['name']);
}

but then maybe i'm not understanding something...


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to