View Single Post
  #1 (permalink)  
Old 10-10-04, 01:07 PM
dannyallen dannyallen is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Serializing a set of arrays

I am trying to serialize a table from my database, which is named "fcc_templates". Now, I want the output from the database to be like this:


Array
(
[1] => Array
(
[template_1] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)
[template_2] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)
[template_3] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)

)

[2] => Array
(
[template_1] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)
[template_2] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)
[template_3] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)

)

)

Each number [1] etc is a skin set id, and the templates are by their name. Now, I can get my script to output this:

Array
(
[1] => Array
(
[install_correct] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)

)

)

But, as you can see, only one template is shown. I want to be able to show all the templates in the [1] array or [2] array or whatever number the skin id is. Here is the code I have so far:

$value = $db->query("SELECT * FROM fcc_templates");
while ($cache1 = $db->fetch_array_assoc($value)){

$newval = array ($cache1[skinid] => array($cache1[callname] => $cache1));

$val .= serialize($newval);

}

echo $val;

echo "<br><br><pre>";
$new1 = unserialize($val);
print_r($new1);
echo "</pre>";

and the serialization seperates each template into its own array. I want each template to be part of the entire skinid array, not it's own big array. Here is what it looks like:


Array
(
[1] => Array
(
[install_correct] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)

)

)


Array
(
[1] => Array
(
[next_template] => Array
(
[tid] => 1
[skinid] => 1
[name] => Installed Correctly
[template] => testing $var
[callname] => install_correct
)

)

)

see, each template is in its own array. How can I fix this?
Reply With Quote