smarty, php, dynamic arrays...

From: Date: Fri, 17 Jan 2003 04:44:46 +0000
Subject: smarty, php, dynamic arrays...
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7241@lists.php.net to get a copy of this message
now let me start by saying I know this isn't 100% a smarty problem, but it is being used in a smarty context, and hopefully somebody smart here can help me out :) My problem is setting an array in a dynamic environment.. a normal multi-dymentinal array would be like this: function db(){ mysql_query("select id,name,price from products where id > 5") ..cut.. while(fetching_array){ $item_array[] = array('id' => $data[id], 'name' => $data[name], 'price' => $data[price]); } return $item_array;} then to smarty as: $smarty->assign('item_array',$item_array); then on the template page under a section run... works great. Now how would this be written if "id,name,price" weren't known before hand? and needed to work it's way into the array dynamically? here's what I got so far: function: $what = "id,name,price"; mysql_query("Select $what from products where id > 5") $results_array = array(); while (fetching_array) { grab = explode(',', $want); for ($g = 0;$g < count($grab);$g++) { $item = $grab[$g]; $item_array[] = array_push($item_array, array( $item => $db->Record[$item])); } return $item_array; } then to smarty... this is close, but not exact. for this example it gives off: Array ( [0] => Array ( [id] => 17811 ) [1] => 1 [2] => Array ( [name] => Sopranos: Complete First Season ) [3] => 3 [4] => Array ( [price] => 78.35 ) [5] => 5 [6] => Array ( [id] => 24531 ) [7] => 7 [8] => Array ( [name] => Sopranos: Complete Second Season ) [9] => 9 [10] => Array ( [price] => 76.17 ) [11] => 11 ) the result of the search is 2 rows .. but what I've gotten is a bunch of un-associated arrays... what am I missing? any help would be great... -- Best regards, guido mailto:sguido@rogers.com

« previous php.smarty.general (#7241) next »