How to store a string array into MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

How to store a string array into MySQL

Post by Mythic Fr0st »

How do I store a string array into MySQL

even better yet, how do I create a "string" array in PhpMyAdmin (for MySQL) or using SQL
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Hmm, vague description.

Separate records.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

feyd wrote:Hmm, vague description.
Has its good side. It's vague enough to point to http://dev.mysql.com/tech-resources/art ... ation.html ;)
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

Code: Select all

$array =  implode( $_POST['array']);
$query = "INSERT INTO table (field) VALUES ('$array')";
mysql_query($query) or die (mysql_error());
implode() did it for me. Otherwise it would just insert the word "array".

-Pete
Last edited by psurrena on Thu Dec 14, 2006 8:30 pm, edited 1 time in total.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ok

Post by Mythic Fr0st »

Thanks, but how would I create it like...

Code: Select all

$array =  implode("array0","array1")
$query = "INSERT INTO field (text) VALUES ('$array')";
mysql_query($query) or die (mysql_error());

etc...? would that work, I need to store 2 values in it first -.-
Last edited by Mythic Fr0st on Thu Dec 14, 2006 5:17 pm, edited 1 time in total.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

For me, it was creating an array from check boxes.

Check out the thread:
viewtopic.php?t=60771
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

buddy... that link points to this thread. :lol:
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

buddy? haha ok...chief

viewtopic.php?t=60450

later pal
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: ok

Post by RobertGonzalez »

Mythic Fr0st wrote:Thanks, but how would I create it like...

Code: Select all

$array =  implode("array0","array1")
$query = "INSERT INTO field (text) VALUES ('$array')";
mysql_query($query) or die (mysql_error());

etc...? would that work, I need to store 2 values in it first -.-
What have you tried so far?
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

nvm

Post by Mythic Fr0st »

Nevermind, thanks guys, got a friend on trillion to help me with it
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Did you ever try anything on this?
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Yep

Post by Mythic Fr0st »

Yep, and what I did didnt work:P
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

fyi, you might want to read the manual on what arguments implode is supposed to take

Code: Select all

implode()
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Code: Select all

serialize()
and

Code: Select all

unserialize()
are what you're looking for, I think.

Cheers,
Kieran
Post Reply