[PHP] MySQL and PHP arrays
Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL and PHP arrays
On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL and PHP arrays
Serializing it would be the best way: seralize($myArray) then you can get the array back using unseralize($serializedarray) -Original Message- From: {R}ichard Ashton [mailto:[EMAIL PROTECTED] Sent: 10 March 2003 14:31 To: [EMAIL PROTECTED] Subject: [PHP] MySQL and PHP arrays Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? {R} -- 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] MySQL and PHP arrays
On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- 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] MySQL and PHP arrays
You get at the data through $array = mysql_result($result,0,0); Mike {R}Ichard Ashton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- 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] MySQL and PHP arrays
mysql_fetch_array($result) works too. It fetches the data from the current row and is used in conjunction with a while loop: while($array=mysql_fetch_array($result)) { //stuff to do with the current array } Robbert van Andel -Original Message- From: Mike Mannakee [mailto:[EMAIL PROTECTED] Sent: Monday, March 10, 2003 8:45 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] MySQL and PHP arrays You get at the data through $array = mysql_result($result,0,0); Mike {R}Ichard Ashton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php