Multiple inserts into a database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The kind of thing I'm looking to do is to insert a variable number of
records into a database as a consequence of a form entry.

I am using PHP with a MySQL database to store information that is
vaguely analogous to a fast food online ordering system. I have a table
containing individual items with a short code for each item.  A user
would enter the short code and this gets stored.

x-----------------------------------x
| item_id | item_name  | item_code  |
|    1	  |   Burger   |  bur       |
|    2    |   Fries    |  fr        |
|    3    |   Cola     |  co        |
x-----------------------------------x

What I want to do is have a way of letting the customer order multiple
items with one code, e.g. entering "meal" results in burger/fries/cola
being entered in an order table.

I realise i need in effect a translation table, that contains meal with
references to the items burger/frires/cola, something like below so I
could do something "SELECT item_id FROM deal WHERE deal_name = meal" to
get the individual items for the "meal"

x-----------------------------------x
| deal_id | deal_name  | item_id    |
|    1	  |   meal     |  1         |
|    2    |   meal     |  2         |
|    3    |   meal     |  3         |
x-----------------------------------x

So far, I can understand what I need to do to achieve this.  What I am
having trouble trying to understand what to do and how best to do it, is
to get the individual elements of the meal entered into an order table.

Would a foreach statement that works through the array produced by the
"meal" query, inserting each item in the meal be the best way forward?

The "deals" on offer would vary in size e.g. burger+fries/burger+fries
+cola+ice cream+toy so whatever solution is use, would have to cope with
changing size.

Note:  As you might have noticed already, I'm not the world's best
PHP/MySQL programmer but I'm ready and willing to try stuff.


Danny

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux