I wrote previously a few lines of code that would pull the field names from a table and then generate strings based on the names with correlating data.
My problem is that I would like to push this into an array, but for some reason it will not create the array.
This is my array line.
$$fields[$i] = array($a=>$row[$i]);
I've used a similar line for single row calls:
$$fields[$i] = $row[$i];
This works fine. It will set fielda to $fielda with a value of $row[$i].
This is the code in context:
function pull_data($table,$conditions,$sfields = "*"){
$sql = "select $sfields from $table $conditions";
$result = mysql(database,$sql);
if(empty($sfields) || $sfields == "*"){
while($f < mysql_num_fields($result)){
$fields[$f] = mysql_field_name($result, $f);
$f++;
}
} else {
$fields = explode(",",$sfields);
}
$a=0;
while($row = mysql_fetch_row($result)){
$i=0;
while($fields[$i]){
$$fields[$i] = array($a=>$row[$i]);
$i++;
}
$a++;
}
}
The reason I'm coding like this is to avoid repetition.
if you have any ideas why the array line won't work, or a solution to make it work, I'd appreciate it.
Thanks.
Ron