473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Best layout

18
I am stumped as to the best layout of a database. It is an inventory database. In it are several (9) vendors each with 2-300 items that we order. Each item has an item#, description and cost. We will have 8 sites that place orders, though not all sites order from all vendors or should have access to order the entire vendor catalog of items.

Suggestions?

Thank you in advance
MO
Oct 3 '09 #1
8 2513
Atli
5,058 Expert 4TB
Hey.

What have you tried so far?

The vendors and their items could be placed in two separate tables, where the vendors would be stored in one table, and the items in another. The items would be linked to the vendor table with a foreign key, which would indicate which vendor the item belongs to.
(A typical 1:N relationship.)

The sites could be placed in their own table, and a second table could be created that links the sites to the items they have access to. The link table would just contain two columns: a foreign key column linking to the sites, and another foreign key column linking to the items.
(A typical N:M relationship.)

Does that make sense?
Oct 4 '09 #2
monion
18
I used 2 table types
Table type #1 was named after the vendor, it contained the generic column names of: item#, description, cost and a column for each clinic (simple Y/N toggle)
I did a table of type#1 for each vendor.
I then just imported a .csv from excel that had the info and served it up as a basic webpage with one input field for each item so the user could enter a quantity.

Table type #2 was named after each clinic & vendor. Each column was named with item#, item#/description, item#/cost and item#/quantity.
The first three columns were from the table #1 info, the last column, item#/quantity was from my form input fields.

This just seems like the wrong way to be doing this...

As to your ?, I understand everything but the 2nd part of the 2nd part:
"..., and a second table could be created that links the sites to the items they have access to. The link table would just contain two columns: a foreign key column linking to the sites, and another foreign key column linking to the items."
Oct 5 '09 #3
Atli
5,058 Expert 4TB
@monion
That is indeed the wrong way to design a DB.

You tables and columns should never be named using actual data. Like creating individual tables for each vendor. You database should be able to scale perfectly without you ever having to alter the actual tables.

If you would have to create a new table or column to add data to your database, it is (usually) not designed properly.

@monion
Consider this:
Expand|Select|Wrap|Line Numbers
  1. +--------+ +--------------+
  2. | vendor | | item         |
  3. +--------+ +--------------+
  4. | id PK  | | id PK        |
  5. | name   | | name         |
  6. +--------+ | price        |
  7.            | vendor_id FK |
  8.            +--------------+
  9.  
  10. +--------+ +--------------+
  11. | site   | | site_item    |
  12. +--------+ +--------------+
  13. | id PK  | | item_id FK   |
  14. | name   | | site_id FK   |
  15. +--------+ | allowed      |
  16.            +--------------+
The "site_item" table there is the important part. It links the items in "site" with the items in "item", so if you ever need to find out whether a particular site is allowed to sell a specific item, you would search the "site_item" table for the row that has the correct IDs and then just read the "allowed" value.

Does that make more sense?
Oct 5 '09 #4
monion
18
Would I make a seperate table just for the quantities ordered? and make that a FK to what? to display an invoice yielding Site name, vendor, item#, item price and quantity ordered.

Thank you for your patience...
MO
Oct 5 '09 #5
Atli
5,058 Expert 4TB
You could make an order system by adding two tables. The first on to list the actual order and who owns the order (which site), and a second table to contain the items in the order, which would be linked to both the order table and the item table, in a similar way the "site_item" table was.

Something like:
Expand|Select|Wrap|Line Numbers
  1. +------------+ +--------------+
  2. | order      | | order_items  |
  3. +------------+ +--------------+
  4. | id PK      | | order_id FK  |
  5. | site_id FK | | item_id FK   |
  6. +------------+ | qantity      |
  7.                +--------------+
Oct 5 '09 #6
monion
18
On the form submission, how would I go about submitting multiple items ordered? Would I just keep posting order_id, item_id and quantity over and over until all items off of the form have been submitted? I have only worked a form where a post went to unique fields one time.
ex.: lastname
firstname

not ex:
lastname
firstname
differentlastname
firstname
3rddifferentlastname
differentfirstname

etc.

Thanks,
MO
Oct 6 '09 #7
monion
18
Would I just pack all the values into one array and submit the array as one value?
Oct 6 '09 #8
Atli
5,058 Expert 4TB
You can do something like:
Expand|Select|Wrap|Line Numbers
  1. <intput type="text" name="firstname[1]">
  2. <intput type="text" name="lastname[1]">
  3. <br>
  4. <intput type="text" name="firstname[2]">
  5. <intput type="text" name="lastname[2]">
  6. <br>
  7. <intput type="text" name="firstname[3]">
  8. <intput type="text" name="lastname[3]">
  9. <br>
And PHP would read that as:
Expand|Select|Wrap|Line Numbers
  1. Array(
  2.   [firstname] = Array(
  3.     [1] = Value,
  4.     [2] = Value,
  5.     [3] = Value
  6.   ),
  7.   [lastname] = Array(
  8.     [1] = Value,
  9.     [2] = Value,
  10.     [3] = Value
  11.   )
  12. )
So you could use JavaScript to allow the user to add as many <input> fields as he needs.
Oct 7 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
24
by: delerious | last post by:
Hi, I am designing a web site that will that showcase a bunch of vacation pictures. It will have a banner and a navigation menu (consisting of 13 rectangular images that can be clicked). I am...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
7
by: Hostile17 | last post by:
I'm trying to arrive at a kind of "industry standard" or "best practice" approach to CSS for a policy document aimed at developers, but not necessarily very experienced developers. What does the...
4
by: Will Hartung | last post by:
The designers have handed me a page that has 5 different blocks on it in the center column (in a typical 3 column layout with page spanning headers and footers). The blocks have elaborate...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
4
by: Rudy | last post by:
Hello all! I would like to take a row from a table and display this info in a nice layout. I tried the the reapeater, can't seemm to do too much with that. And I don't want a grid layout. I...
7
by: Rhino | last post by:
I thought I'd take a second to step away from a specific problem and ask a general question about best practices; I know some of the people here are very experienced with CSS. Given the need to...
1
by: LilC | last post by:
I'm creating an application that has a standard layout for all pages. The information that is displayed in the layout will be dynamic based on the user that is logged in. Thus when a page is...
13
by: Justin.Voelker | last post by:
Hello Everyone: I am in search of an easier way to develop pages. My most current website, www.Base2WebDesign.com, has the exact same layout throughout the entire site. Right now I use a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.