473,385 Members | 1,320 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,385 software developers and data experts.

insert into one main table and one detail table in one go without double records

1
Hi everyone,
This is my question/problem.

I have a table with orders and a table with order details.
Clients can order multiple products at once during one order, so one line has to be inserted in the main order table, and multiple order details from the same order in the order detail table.

How do I do this?

Right now if a client orders 5 products during one order, the order detail table looks fine, but also get 5 records in my main order table. It has to be one.
I probably have to change my SQL statement for this, but don't really know how.

Any suggestions?

(renatef_bestellingen is the main ordertable, renatef_besteldetail is the order detail table)

A part of my current code:

Expand|Select|Wrap|Line Numbers
  1. $sql = "INSERT INTO renatef_bestellingen (KLANT_ID, besteldatum, besteluur, leveringswijze, leveringskost) VALUES ('$klantid', '$datum', '$uur','$leveringswijze', '$leveringskost')";
  2. $theresult = mysql_query($sql);
  3.  
  4. $bestelid = mysql_insert_id(); 
  5.  
  6. $sql2 = "INSERT INTO renatef_besteldetail (bestelling_id,product_id,aantal)VALUES (".$bestelid.",'$key','$val')";
  7. $theresult2 = mysql_query($sql2);
about the attachments

the 'renatef_bestellingen' picture shows that 2 records are made with the same info, it should only be 'BESTELLING_ID' with value 26

in the 'renatef_besteldetail' picture everything is correct except for the 'bestelling_id' which both should be value 26

I also added a print screen of more of my code.
thanks in advance for your help! I keep looking myself but it is really urgent so any help is very welcome.
Attached Images
File Type: jpg code.jpg (14.4 KB, 187 views)
File Type: jpg renatef_bestellingen.jpg (8.1 KB, 202 views)
File Type: jpg renatef_besteldetail.JPG (15.1 KB, 162 views)
Oct 11 '09 #1
1 2596
TheServant
1,168 Expert 1GB
Welcome to Bytes. Your image resolution was really bad so I can't see your code. I am a little confused as to what you want... Can you not do something like:
Expand|Select|Wrap|Line Numbers
  1. /* Insert row into renatef_bestellingen */
  2.  
  3. foreach ( $items as $item ) {
    /* Insert row into renatef_besteldetail for each detail */
    }
  4.  
Oct 11 '09 #2

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: ImraneA | last post by:
Hi there Application : Access v2K/SQL 2K Jest : Using sproc to append records into SQL table Jest sproc : 1.Can have more than 1 record - so using ';' to separate each line from each other.
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
0
by: ImraneA | last post by:
Hi there I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K. Wish to provide some knowledge gained back to community - hopefully help others. 1.Question how do you test stored...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
10
by: surya | last post by:
i have a table name is HH table it has two columns 'hhno' and hhname' HH tabele hhno hhname 100 suresh 101 baba 103 ram...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.