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

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

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);
  4. $bestelid = mysql_insert_id(); 
  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 2595
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 */
  3. foreach ( $items as $item ) {
    /* Insert row into renatef_besteldetail for each detail */
Oct 11 '09 #2

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

Similar topics

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...
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.
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,...
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...
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...
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...
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...
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...
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...
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...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
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...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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$) { } ...
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...
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
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.