PHP beginner DB design questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WestChi
Forum Newbie
Posts: 1
Joined: Mon Apr 14, 2008 6:30 pm

PHP beginner DB design questions

Post 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
samb0057
Forum Commoner
Posts: 27
Joined: Wed Mar 26, 2008 9:51 am

Re: PHP beginner DB design questions

Post 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>';
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP beginner DB design questions

Post 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.
Post Reply