PHP beginner DB design questions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

PHP beginner DB design questions

WestChiWestChi Posts: 1Member
I am trying to make a database driven website about a collecting hobby. The problem I am having is how do you design it properly.

Example:
Table A
companyID, companyName, companyBio

Table B
itemID, itemName, colorID, price

Table C
colorID, colorName

How do I design the input and output forms so that instead of having to know the companyID and colorID for an item they can select the companyName or see the colorName on the query results form?

Thanks

Comments

  • tvientitvienti Posts: 230Member
    : I am trying to make a database driven website about a collecting
    : hobby. The problem I am having is how do you design it properly.
    :
    : Example:
    : Table A
    : companyID, companyName, companyBio
    :
    : Table B
    : itemID, itemName, colorID, price
    :
    : Table C
    : colorID, colorName
    :
    : How do I design the input and output forms so that instead of having
    : to know the companyID and colorID for an item they can select the
    : companyName or see the colorName on the query results form?
    :
    : Thanks
    :
    :

    I like to write a function that takes an array of ID => Name and turns it into a list of elements. For example:

    [code]
    function AssocToOptions($assoc)
    {
    $options = array();
    foreach ($assoc as $ID => $Name)
    {
    $ID = htmlentities($ID); // just to be safe
    $Name = htmlentities($Name); // again...
    $options[] = "$Name";
    }

    /* I join them with a
    for source readability */
    return implode("
    ", $options);
    }
    [/code]

    Now it's just a question of selecting the ID's and names from the database, building them into an assoc array of ID => Name, and passing it to this function. Then wrap the results of the function in a and you're good.
Sign In or Register to comment.