Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Putting Arrays into MySQL
Old 10-05-2007, 04:56 PM Putting Arrays into MySQL
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Hey, I've really been thinking about this lately.
Is there any way to put Arrays into MySQL, for example:

PHP Code:
$array[0] = "yes";
$array[1] = "no";

$sql '`field` = '.$array.''
Currently I've never got it to work (If anything i get the word 'Array' back, but no values). So I end up using explodes, for example.

PHP Code:
$array "yes|/|no";

$sql '`field` = '.$array.'';

// do SQL, and receive it back as say...$hobbit.

$hobbit explode($hobbit"|/|"); 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
 
Register now for full access!
Old 10-05-2007, 07:08 PM Re: Putting Arrays into MySQL
Experienced Talker

Posts: 41
Trades: 0
You want to look at the php functions SERIALIZE and UNSERIALIZE

They basically convert the array to and from a string representation for purposes like this!
__________________

Please login or register to view this content. Registration is FREE
- Need answers? Ask it online.
Create powerful online surveys with ease in minutes!

Please login or register to view this content. Registration is FREE
Triexa is offline
Reply With Quote
View Public Profile
 
Old 10-05-2007, 07:31 PM Re: Putting Arrays into MySQL
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by Triexa View Post
You want to look at the php functions SERIALIZE and UNSERIALIZE

They basically convert the array to and from a string representation for purposes like this!
Thank you ^^ This worked just the way i wanted it too
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-06-2007, 06:12 AM Re: Putting Arrays into MySQL
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
It's ok, 'Triexa' helped me. If you want to put an array into SQL you need to do something simlar to the following:

PHP Code:
$array[0] = "yes";
$array[1] = "no";

$sql '`field` = '.serialize($array).''

// do SQL, and receive it back as say...$hobbit.
$hobbit['field'] = unserialize($hobbit['field']); 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Putting Arrays into MySQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.98804 seconds with 12 queries