473,398 Members | 2,188 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,398 software developers and data experts.

Possibly a relational DB problem

Hi,

I've recently become really stuck trying to program a shopping cart
for a site i'm designing.

I have 2 Tables

OrderItems
Orders

Which need to be updated during the update process, the data that is
to be updated is stored in an array.

As i understand it, i need to update the the Orders Table, get an
OrderID (which i have set to an auto increment number) then update the
OrderItems with the following info

OrderID
ProductID
ProductQty
CustomerID

I've done this using 3 fairly messy sql statements and feel their must
be a better way to do this using some sort of relational database?

I'm really stuck here, and would appreciate any help that anyone could
offer.

Kind Regards,

Ian
Jul 17 '05 #1
5 1231
ia*******@gmail.com says...
As i understand it, i need to update the the Orders Table, get an
OrderID (which i have set to an auto increment number) then update the
OrderItems with the following info I've done this using 3 fairly messy sql statements and feel their must
be a better way to do this using some sort of relational database?


Without any clue as to what brand of database you are using (MySQL?), I
suspect that you should be able to do it with just 2 SQL statements.

1. Insert new record into Orders table (using a "returning" clause to set
an order_id variable if using Oracle or any DBMS that supports this
syntax, or if MySQL immediately using the mysql_insert_id() function); and

2. Insert records into OrderItems table.

Geoff M
Jul 17 '05 #2
I noticed that Message-ID:
<13**************************@posting.google.com > from Ian N contained
the following:
As i understand it, i need to update the the Orders Table, get an
OrderID (which i have set to an auto increment number) then update the
OrderItems with the following info

OrderID
ProductID
ProductQty
CustomerID


Shouldn't CustomerID be stored on the Orders table?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
Geoff M <gm************@scu.edu.au> wrote in message news:<MP************************@news.individual.n et>...
ia*******@gmail.com says...
As i understand it, i need to update the the Orders Table, get an
OrderID (which i have set to an auto increment number) then update the
OrderItems with the following info

I've done this using 3 fairly messy sql statements and feel their must
be a better way to do this using some sort of relational database?


Without any clue as to what brand of database you are using (MySQL?), I
suspect that you should be able to do it with just 2 SQL statements.

1. Insert new record into Orders table (using a "returning" clause to set
an order_id variable if using Oracle or any DBMS that supports this
syntax, or if MySQL immediately using the mysql_insert_id() function); and

2. Insert records into OrderItems table.

Geoff M


Hi Thanks for the response Geoff,

How do i use the mysq_insert_id() function and wat will it do?
I use Access at work and would link the tables and do an inner join on
the tables in the sql statement. I've always preferred using Mysql and
PHP, but seem to have been totally stuck by this.

Cheers for the response though!
Jul 17 '05 #4
ia*******@gmail.com says...
1. Insert new record into Orders table (using a "returning" clause to set
an order_id variable if using Oracle or any DBMS that supports this
syntax, or if MySQL immediately using the mysql_insert_id() function); and
How do i use the mysq_insert_id() function and wat will it do?
http://www.php.net/manual/en/functio...-insert-id.php
I use Access at work and would link the tables and do an inner join on
the tables in the sql statement. I've always preferred using Mysql and
PHP, but seem to have been totally stuck by this.


MS Access ... <shudder> ... no idea how to do it on that. I use Oracle
and MySQL only.

Geoff M
Jul 17 '05 #5
I noticed that Message-ID:
<13*************************@posting.google.com> from Ian N contained
the following:

How do i use the mysq_insert_id() function and wat will it do?


It does what it says in the manual...

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rolf Hemmerling | last post by:
Hello ! Beginner's question: What ist the easiest way to store and save objects in a file generated by a C++ program, by using the "standard C++ library" and/or "Standard Template Library (...
34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
18
by: comcast | last post by:
Hello all, I am developing an interface system for an application I was written. This interface will connect to other system to share information. I would like to use xml and xsl to generically...
0
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies...
1
by: mirnazim | last post by:
Hi, I have to develop a web based information system for an educational institution. It is going to be a 100% OO code. Therefore I also need an Object Relational Mapper. I have not used any object...
49
by: Mike MacSween | last post by:
I frequently hear that there isn't a commercially available dbms that fully implements the relational model. Why not? And which product comes closest. Mike MacSween
14
by: AliceB.Toklas | last post by:
In my Absolute Beginner's Guide to C book by Greg Perry where it is instruction how relational operators work it gives the following example: int i = 5; so the following statement is true: ...
24
by: sonos | last post by:
Hi, I am working on a program to archive data to disk. At what point is it best to use a relational database like MySQL as the backend instead of a C program alone? Thanks to any and all...
1
by: jsparks57 | last post by:
I want to cin two characters for any of the six relational operators. '>=' no problem or '!=' no problem. The problem is for reading single character '<' and '>'. My code wants to read two...
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:
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.