A question of logic.. PHP/MySQL

Discussion in 'PHP' started by jack_ss, Jan 16, 2009.

  1. #1
    I'm fairly proficient with PHP but a lousy programmer. I need to figure this out for a project and I'm kinda drawing a blank. Maybe someone out there can point me in the right direction.

    I have a table of groups and a table of options I need to somehow generate a list of all possible combinations using one option from each group.

    Example:
    Table 1 (Groups):
    id|name
    -------
    1|AAA
    2|BBB
    3|BBB
    Code (markup):
    Table 2 (Options):
    id|parent|name
    1|1|A1
    2|1|A2
    3|1|A3
    4|2|B1
    5|2|B2
    6|2|B3
    7|3|C1
    8|3|C2
    9|3|C3
    Code (markup):
    Desired Result:
    A1B1C1
    A1B1C2
    A1B1C3
    A1B2C1
    A1B2C2
    A1B2C3
    A1B3C1
    A1B3C2
    A1B3C3
    A2B1C1
    A2B1C2
    A2B1C3
    A2B2C1
    A2B2C2
    A2B2C3
    A2B3C1
    A2B3C2
    A2B3C3
    etc..
    Code (markup):
    Your expert advice is much appreciated.
     
    jack_ss, Jan 16, 2009 IP
  2. cont911

    cont911 Peon

    Messages:
    50
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    would you like to solve this in mysql?
    Is it correct that if you had 4 groups, then first combination would look like A1B1C1D1?

    how many groups do you have for your task?
     
    cont911, Jan 16, 2009 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    I Think you need some kind of recursive function.
     
    Kaizoku, Jan 17, 2009 IP