Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am working on an online food ordering system for restaurants. Basically restaurants will upload their menus for customers to order food they desire from anywhere.

Now my problem is how to create and implement a database model for multiple orders.

Example:

Taylor(customer) makes this order comprising four food items. How will this order be saved in one row with a reference to Taylor

Pizza 20.00 from restaurant-1
burger 18.00 from restaurant-2
Pepsi 3.00 from restaurant-1
salad sauce 20. from restaurant-3
Posted
Updated 21-Mar-14 23:14pm
v3

-First of all you have to create yable for Food(Menu Items)
-Then You have to create Table for restuarants
-Now you can insert into customer tables just ID of a Menu Items And Restaurants


Like THAT

custID | Name | Contact | Item | Resturant

1 | Nirav | 73838032188 | 1(ID of Pizza | 2 (ID of Restuarant)
 
Share this answer
 
You don't. Don't even think about using one row - it won;t work well, because you have no idea how many items any customer might order.

Suppose you say "nobody is going to order more than 40 items". What happens when they do?
And, what if Taylor also puts in an order for his mother, at the next table?
Instead, use a number of database tables.
One table holds info on the customer, and has a primary key which is the customer ID - this can include the password hash, the user name, and where he is.
A second holds customer orders - this had a primary key which is the order number, and a foreign key which is the customer, and a datetime which is when it was placed, and "completed", "paid" and "total" columns if you need them (and you probably do)
A third table holds the items he can order: primary key is an ItemID, it also holds the price, and the number you can serve (so you can remove items when the kitchen "runs out")
A fourth table holds order details: Primary key is an OrderItemID (but this is just a unique value to the table), with foreign keys to the Orders table, Items table and a "number of items ordered" column.

Sounds complicated? Yes, a bit - but it's a lot, lot simpler than trying to faff about with just one table, trust me!

Try it on paper with a pencil - you'll see what I mean!
 
Share this answer
 
Comments
akashjg 22-Mar-14 6:13am    
Thanks OriginalGriff but in my project there are many Restaurants..
how can i manage it

pls help..
OriginalGriff 22-Mar-14 6:25am    
So you add another table for Restaurant - and you add another foreign key to the Orders table which refers to the restaurant - since an order only makes sense if it is to come from one restaurant.
If a order is spread over several restaurants, then the restaurant needs to be linked to the OrderDetail table instead (and possibly the order item table as well, since not all kitchens will cook all items).
And you will need to look at a restaurant based "cook list" being created for each order, o send to the separate locations - you don't want the full details going to 2 places as they might assume it's all foe them to do!
akashjg 22-Mar-14 6:47am    
thanks OriginalGriff.

i have one more question how to manage menu items of all Restaurants?
because mostly all Restaurants has same items but different price..
OriginalGriff 22-Mar-14 6:57am    
Then you need to have different items in Items table, with a separate price and a link to the ResturantID
So if two restaurants do a Bacon Pizza you have two separate items:
Item Id Description Price Resturant
1234 Bacon Pizza 12.43 76
1235 Bacon Pizza 14.77 21

And so on.
It's complicated, but so is the data you are playing with. It's not to bad to work with though - you can use JOIN to pick up all the relevant info in one command, usually.
As I said - try it on paper and you will see what I mean!
akashjg 22-Mar-14 7:15am    
thank for helping...
it's help me a lot..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900