Re: [PHP] Re: storing array in mysql

2001-08-01 Thread elias

Well, you have to treat all the user's input as a string actually. So
basically only one data type.
Now as for splitting and joining, you can make up a splitting character
let's say: |*^| and see if the user entered this in some of his input.
It's really rare to have such weird combination of characters to be inputed
by users.
Use javascript to validate before submitting.

well yes, The size of string produced by serialize is huge, why not trying
to compress it before storining it? bzcompress()


"Warren Vail" <[EMAIL PROTECTED]> wrote in message
001a01c119ce$88a8b640$b5887ed8@nicker">news:001a01c119ce$88a8b640$b5887ed8@nicker...
> I never seem to be lucky enough to be sure of the type of data stored in a
> php array, since php handles mixtures of types so forgivingly, and because
> most of my data comes from forms, with users key in what they like,
> including double and single quotes, parentheses (and especially commas,
how
> do you prevent breaking up your array and putting it back together with a
> different row count because someone keyed in a comma?), etc.  I would
think
> you would have to go to a lot of trouble to make sure that an array
contains
> only numeric data, or only strings that did not contain problem causing
> characters.
>
> You are right about more space being required for serialize, I often have
to
> resort to TEXT data types to provide enough space in the column for data
> (65k runs out fast), and that is a bit slower as well.
>
> Warren
>
> -Original Message-
> From: elias [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 8:09 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Re: storing array in mysql
>
> 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" <[EMAIL PROTECTED]> wrote in message
> 001701c119c8$562b0ca0$b5887ed8@nicker">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:[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:
> > > 
> > > name
> > > 
> > >
> > > 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]
>
>



-- 
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]




RE: [PHP] Re: storing array in mysql

2001-07-31 Thread Warren Vail

I never seem to be lucky enough to be sure of the type of data stored in a
php array, since php handles mixtures of types so forgivingly, and because
most of my data comes from forms, with users key in what they like,
including double and single quotes, parentheses (and especially commas, how
do you prevent breaking up your array and putting it back together with a
different row count because someone keyed in a comma?), etc.  I would think
you would have to go to a lot of trouble to make sure that an array contains
only numeric data, or only strings that did not contain problem causing
characters.

You are right about more space being required for serialize, I often have to
resort to TEXT data types to provide enough space in the column for data
(65k runs out fast), and that is a bit slower as well.

Warren

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

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" <[EMAIL PROTECTED]> wrote in message
001701c119c8$562b0ca0$b5887ed8@nicker">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:[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:
> > 
> > name
> > 
> >
> > 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]



-- 
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]




Re: [PHP] Re: storing array in mysql

2001-07-31 Thread elias

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" <[EMAIL PROTECTED]> wrote in message
001701c119c8$562b0ca0$b5887ed8@nicker">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:[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:
> > 
> > name
> > 
> >
> > 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]




RE: [PHP] Re: storing array in mysql

2001-07-31 Thread Warren Vail

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:



now to reget the array, you can select it back from MySql and split it as:


//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:
> 
> name
> 
>
> 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]




[PHP] Re: storing array in mysql

2001-07-31 Thread elias

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

you can store in in MySql as:



now to reget the array, you can select it back from MySql and split it as:


//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:
> 
> name
> 
>
> 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] Re: storing array in mysql

2001-07-31 Thread Richard Lynch

> I want to store the results of a multiple select input box in a mysql
> db.

Store each possible selection as a different record in a separate table and
then create a three-table join for which selections match which "main"
records.

You'll be tearing your hair out for the rest of time otherwise.

Here's what I mean:

Assume table "foo" is what you have right now, and you've been trying to
stuff things into "lists_actual" (that is you, isn't it?) for the names
selected.  Do this instead:

[UNTESTED CODE!]

create table foo(
foo_id int(11) auto_increment not null primay key,
foo text
);
insert into foo(foo) values('Foo 1');
insert into foo(foo) values('Foo 2');

create table name(
name_id int(11) auto_increment not null primary key,
name text
);
insert into name(name) values('a');
insert into name(name) values('b');
insert into name(name) values('c');
insert into name(name) values('d');
insert into name(name) values('e');

create table foo_name(
foo_id int(11),
name_id int(11)
);

$foo\n";
}
exit;
}
if (isset($names)){
$query = "delete from foo_name where foo_id = $foo_id";
mysql_query($query) or die(mysql_error());
while (list($name_id, $name) = each($names)){
$query = "insert into foo_name (foo_id, name_id) values($foo_id,
$name_id)";
mysql_query($query) or die(mysql_error());
}
}
$query = "select foo_id, foo from foo where foo_id = $foo_id";
$foos = mysql_query($query) or die(mysql_error());
list($foo_id, $foo) = mysql_fetch_row($foos);
echo $foo, "\n";
?>
 METHOD=POST>
>

$name\n";
}
?>




--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
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]