Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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
Sign In or Register to comment.