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

Can you show me the two scripts you were saying? Thanks

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

Wait, Pardon me but please can you elaborate it more?

Member Avatar for diafol

show the data structure

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.