Page 1 of 1

PHP beginner DB design questions

Posted: Mon Apr 14, 2008 6:31 pm
by WestChi
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

Re: PHP beginner DB design questions

Posted: Fri Apr 18, 2008 11:59 am
by samb0057
$query = mysql_query('select * from `companies`');

echo '<select name="company">';
while ($row = mysql_fetch_assoc($query)) {
echo '<option value="' . $row['companyId'] . '">' . $row['companyName'] . '</option>';
}
echo '</select>';

Re: PHP beginner DB design questions

Posted: Fri Apr 18, 2008 6:39 pm
by califdon
WestChi wrote: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
You need to learn about basic kinds of form components, such as list boxes (SELECT elements, in HTML). And if you don't already have a firm grasp of relational database principles, you need to study that. There are lots and lots of tutorials available online. Try using a search engine, using key words like perhaps: html tutorial select and database relational tutorial.