csv, array or alternative in mysql table?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kiqyou_vf

    csv, array or alternative in mysql table?

    im sort of a newbie to all of this and my terminology isnt accurate but
    i have a couple simple questions. ive been looking around for a way to
    insert multiple and seperate strings (like an array or a csv file)
    inside of one row "cell" in a MySQL table. for examlpe id like to
    insert "review1... , review2..., review3..., review4..." inside a row
    "cell". id also like to be able to do a loop on them so i can format
    each string. is it possible to insert an array into a "cell"? anyway,
    if you could direct me in the right direction, i can figure the rest
    out for MySELF. THANKS!

  • Kenneth Downs

    #2
    Re: csv, array or alternative in mysql table?

    kiqyou_vf wrote:
    [color=blue]
    > im sort of a newbie to all of this and my terminology isnt accurate but
    > i have a couple simple questions. ive been looking around for a way to
    > insert multiple and seperate strings (like an array or a csv file)
    > inside of one row "cell" in a MySQL table.
    > for examlpe id like to
    > insert "review1... , review2..., review3..., review4..." inside a row
    > "cell". id also like to be able to do a loop on them so i can format
    > each string. is it possible to insert an array into a "cell"? anyway,
    > if you could direct me in the right direction, i can figure the rest
    > out for MySELF. THANKS![/color]

    I have no idea about MySQL but Postgres does this. I'm guessing thats not
    an option for you.

    There are about a million reasons why you do not want to do this. The
    normal approach is to create a second table and put each value into a row
    in that table, something like this:

    create table parent (
    somekey char(10),
    ..other columns..)

    create table child (
    somekey char(10),
    column1 char(10))

    The idea is that the common column "somekey" links values from the child to
    the parent.

    --
    Kenneth Downs
    Secure Data Software, Inc.
    (Ken)nneth@(Sec )ure(Dat)a(.com )

    Comment

    • kiqyou_vf

      #3
      Re: csv, array or alternative in mysql table?

      i THINK i see what your sayin, each row on the child table is linked to
      a certain column in the parent table?

      Comment

      • Kenneth Downs

        #4
        Re: csv, array or alternative in mysql table?

        kiqyou_vf wrote:
        [color=blue]
        > i THINK i see what your sayin, each row on the child table is linked to
        > a certain column in the parent table?[/color]

        Yes, that's it. In PHP you can loop through these with code like the
        following (assuming postgres, substitute mysql or whatever as appropriate):

        $results = pg_query(
        "select column1
        from child
        where somekey = '$valueofintere st'");
        while ($row = pg_fetch_array( $results) {
        ...do something with entry
        }

        Buy one of Celko's books on db design, or ask a lot of questions over in
        comp.databases, it will really be a big help.

        --
        Kenneth Downs
        Secure Data Software, Inc.
        (Ken)nneth@(Sec )ure(Dat)a(.com )

        Comment

        Working...