What I have used to store an array in mysql is;

$value = addslashes(serialize($array));
$query = "INSERT INTO table (column) VALUES (\"$value\")"

and upon retrieval
$query = "SELECT column FROM table";
......
while($row = mysql_fetch_array($result)) {
        $value = unserialize(stripslashes($row["column"]));
}

Note: serialize allows me to store the array in a single column and
addslashes makes the data mysql safe (i.e. allows me to store quotes in the
column, just in case they are in the array).

Warren Vail

-----Original Message-----
From:   elias [mailto:[EMAIL PROTECTED]]
Sent:   Tuesday, July 31, 2001 4:05 AM
To:     [EMAIL PROTECTED]
Subject:        [PHP] Re: storing array in mysql

when you submit this form, PHP will give a array variable called $name

you can store in in MySql as:

<?
// will make the $name as a comma seperated string
$str = join(",", $name);
insert into tablename(id, value) VALUES(null, '$str');
?>

now to reget the array, you can select it back from MySql and split it as:
<?
  $name = split(",", $str);
?>

//elias
"Matthew Delmarter" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi all,
>
> I want to store the results of a multiple select input box in a mysql
> db. The box looks like this:
> <select name='name[]' size='5' multiple>
> <option value='id'>name</option>
> </select>
>
> I cannot seem to store the array in a database and then output the
> result using foreach. Any tips?
>
> Regards,
>
> Matthew Delmarter
> Web Developer
>
> AdplusOnline.com Ltd
> www.adplusonline.com
>
> Phone: 06 8357684
> Cell: 025 2303630
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to