RE: [PHP] storing array in mysql

From: Date: Tue, 31 Jul 2001 03:34:20 +0000
Subject: RE: [PHP] storing array in mysql
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60304@lists.php.net to get a copy of this message
Hi Ben, This is a section of the insert statement I used ($lists_actual is the array): $lists_actual = serialize($lists_actual); Then : INSERT INTO $table (lists_actual) VALUES ('$lists_actual') When I look in the db there is serialized data there - it appears like this: a:4:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";i:3;s:1:" When I output this to the screen I get the same as above. But when I try to echo the unserialized result I get nothing. I am using: echo $db_result->lists_actual (nothing is returned) If I try to display the result using foreach I get the warning "Invalid argument supplied for foreach()". I am using: $array = unserialize($db_result->lists_actual); foreach($array AS $val) { echo $val; }; I hope the problem is clear, I am thoroughly confused at this stage! I should admit that I am only just getting used to arrays... Matthew -----Original Message----- From: Ben Bleything [mailto:bleythbe@mailbox.orst.edu] Sent: Tuesday, July 31, 2001 3:03 PM To: 'Matthew Delmarter' Subject: RE: [PHP] storing array in mysql Have you tried serialize()'ing it before storing and then unserialize()'ing it afterwards? http://www.php.net/serialize http://www.php.net/unserialize => Ben -----Original Message----- From: Matthew Delmarter [mailto:matt@adplusonline.com] Sent: Monday, July 30, 2001 8:10 PM To: PHP Mailing List Subject: [PHP] storing array in mysql 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

« previous php.general (#60304) next »