0

hi all,

Im after a little help here.

I have a md array stored as text in mysql.

what i need to do is get it out (which ive done), then store it as a real array so i can loop through it to output as a csv file (which i can do fine)

any suggestions would be appreciated.

regards

paul

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by whiteyoh
0

hi,

getting out is just a normal mysql fetch array. The csv bit is using

fopen (the data);
fputs ("from above");
fclose (fopen variable);

then i just use readfile to output the file

0

ok here goes,

the database holds the following as a string
Array
(
[firstname] => thefirstname
[lastname] => thelastname
[email] => the email
[gender] => Male
[dob] => Array
(
[day] => 16
[month] => 3
[year] => 1978
)

[interested] => Array
(
[bread] => 1
[milk] => 1
)

[agree] => 1
[x] => 53
[y] => 15
)

i get it out using the normal method.....

$anarray = array();
while ($row = mysql_fetch_array ($the query)){


$anarray[] = $row['the column containing the string'];

Now that its in an array, i need to loop through the array, turning it into a real array to the parse to a csv file.

as for the code, it will look something like this

<?php

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd'),
    array('123', '456', '789'),
    array('"aaa"', '"bbb"')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);
?>

What i need help with is splitting down the string. what i have so far is just basic stuff using str_replace and explode but im getting lost

0

also, the bit with "bread" and "milk" may contain many different things so i believe id need to use the $$item to find all of the unique names

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.