SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    arrays and MySQL

    can i store an array in a MySQL field? and if i can how do i do it?

    i have an idea how to do it but i dont know if it would work.

    if i store the values in a feild as folows:

    'blue','red','yellow' ect

    then i connect to the database and then carry out the following function

    $colours = array($row[colours]);

    would that work?
    hmm...

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, this will not work if you use the array function. $colours[0] will end up holding the value 'blue','red','yellow' instead of $colours[0] holding 'blue', $colours[1] holding 'red', etc.

    What you CAN do is explode the string like so:

    PHP Code:

    <?php

    $colours 
    explode(",",$row[colours]);

    /* now colours will be an array */
    echo $colours[0];

    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or use serialize/unserialize (http://www.php.net/serialize)

    hadley


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •