Re: [PHP] saving and retrieving an array from a database

2006-08-07 Thread Richard Lynch
On Mon, August 7, 2006 7:52 am, [EMAIL PROTECTED] wrote:
> ok this seem to work but how do I bring it back? This is what I have
> so far.
>
>  $first[] = array('appple', 'pear', 'banana');
> $second = serialize($first);

Store $second in the DB here.

It's just a big long-ass string at this point.

You can use echo $second; to see what it looks like.


[cue clock fast-forward visual sequence]

Pull $second (or whatever you want to call it) out of the database.

It's just a big long string.

> $third[]= unserialize($second);

This de-constructs that big string into an array, and you are back in
business.

> echo $second; //outputs serialized data
> echo $third[1];
>
> ?>

NOTE:
90% of the time, you should be putting each array item into the
database separately, so you can use SQL to retrieve only the bits you
need instead of schlepping the whole thing back and forth all the
time...

If you are new to programming, think long and hard about what you will
be doing with these array elements, and if you plan on using PHP to
search/sort/filter them at some point, don't do that.  Put them in as
individual data in the DB.

If you always use the whole array, and never search it, sort it, or
filter it down to fewer elements, and are just shuffling it
back-and-forth, then serializing it and storing it en masse is fine.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] saving and retrieving an array from a database

2006-08-07 Thread Peter Lauri
http://se2.php.net/serialize

/Peter

-Original Message-
From: Ross [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 07, 2006 7:19 PM
To: php-general@lists.php.net
Subject: [PHP] saving and retrieving an array from a database

Hi,

I have an array of values. I want to save them with php to a single field in

my database and then retrieve them to an array.


What is the simplest way to achive this?


Ross 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] saving and retrieving an array from a database

2006-08-07 Thread Andrei
Well it seems like u made a mess there with arrays...



>From definition of first I understand it's an array of arrays with
element on position 0 (ZERO) set to an array of apple, pear, banana
elements.
If u serialize it and unserialize it you will obtain same thing...

so at the end of the script you should

echo $third[0];

Andy

[EMAIL PROTECTED] wrote:
> ok this seem to work but how do I bring it back? This is what I have so
> far.
> 
>  $first[] = array('appple', 'pear', 'banana');
> $second = serialize($first);
> $third[]= unserialize($second);
> 
> echo $second; //outputs serialized data
> echo $third[1];
> 
> ?>
> - Original Message - From: "Peter Lauri" <[EMAIL PROTECTED]>
> To: "'Ross'" <[EMAIL PROTECTED]>; 
> Sent: Monday, August 07, 2006 8:23 AM
> Subject: RE: [PHP] saving and retrieving an array from a database
> 
> 
>> http://se2.php.net/serialize
>>
>> /Peter
>>
>> -Original Message-
>> From: Ross [mailto:[EMAIL PROTECTED]
>> Sent: Monday, August 07, 2006 7:19 PM
>> To: php-general@lists.php.net
>> Subject: [PHP] saving and retrieving an array from a database
>>
>> Hi,
>>
>> I have an array of values. I want to save them with php to a single
>> field in
>>
>> my database and then retrieve them to an array.
>>
>>
>> What is the simplest way to achive this?
>>
>>
>> Ross
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] saving and retrieving an array from a database

2006-08-07 Thread ross

ok this seem to work but how do I bring it back? This is what I have so far.


- Original Message - 
From: "Peter Lauri" <[EMAIL PROTECTED]>

To: "'Ross'" <[EMAIL PROTECTED]>; 
Sent: Monday, August 07, 2006 8:23 AM
Subject: RE: [PHP] saving and retrieving an array from a database



http://se2.php.net/serialize

/Peter

-Original Message-
From: Ross [mailto:[EMAIL PROTECTED]
Sent: Monday, August 07, 2006 7:19 PM
To: php-general@lists.php.net
Subject: [PHP] saving and retrieving an array from a database

Hi,

I have an array of values. I want to save them with php to a single field 
in


my database and then retrieve them to an array.


What is the simplest way to achive this?


Ross

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] saving and retrieving an array from a database

2006-08-07 Thread Jim Moseby
> 
> Hi,
> 
> I have an array of values. I want to save them with php to a 
> single field in 
> my database and then retrieve them to an array.
> 
> 
> What is the simplest way to achive this?
> 
> 

http://us3.php.net/serialize

Cheers!

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php