Re: Re: storing array in mysql
| From: | elias | Date: | Tue, 31 Jul 2001 15:09:04 +0000 |
| Subject: | Re: Re: storing array in mysql | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60412@lists.php.net to get a copy of this message | ||
Yes true, you can use serialize.
But since you know the format of your $array variable (which is simply
holding one data type) you can safely use split() and join()
better and smaller when stored in that field because they are comma
seperated.
"Warren Vail" <warren@availabletech.com> wrote in message
news:001701c119c8$562b0ca0$b5887ed8@nicker...
> 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:elias_bachaalany@yahoo.com]
> Sent: Tuesday, July 31, 2001 4:05 AM
> To: php-general@lists.php.net
> 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" <matt@adplusonline.com> wrote in message
> news:NDBBKBIHLCDMDICHLDKGIECOCGAA.matt@adplusonline.com...
> > 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: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>