I've building an aftersales section of a site for a client. The sales themselves are dealt with using 3 tables, salesproducts, salesorders and sales_status. sales_orders is the first table used that has an autoincrement on orderid, i then use mysql_insert_id() to get this id which i then assign to salesproducts, and later sales_status. sales_status holds a var called status which holds one of 3 options: pending, confirmed or returned.
I want to be able to display to the client some basic details about pending sales, this would be the orderid, some basic product details(brand, code, quanitity) and some user information (userid).
This will actually involve 3 tables(i think!), two of the sales tables(s_orders and s_status) and the products table.
This the sql for the tables:
CREATE TABLE sales_status (
orderid int(11) NOT NULL default '0',
userid int(11) NOT NULL default '0',
status text NOT NULL
) TYPE=MyISAM;
CREATE TABLE salesorders (
orderid int(11) NOT NULL auto_increment,
order_date datetime NOT NULL default '0000-00-00 00:00:00',
userid int(11) NOT NULL default '0',
PRIMARY KEY (orderid)
) TYPE=MyISAM;
CREATE TABLE salesproducts (
ordernumber int(11) NOT NULL default '0',
productid int(11) NOT NULL default '0',
quantity int(11) NOT NULL default '0',
userid int(11) NOT NULL default '0'
) TYPE=MyISAM;
CREATE TABLE products (
productid int(11) NOT NULL auto_increment,
brand varchar(255) NOT NULL default 'Epson',
code varchar(255) NOT NULL default 'TO',
printer varchar(45) default NULL,
rrp decimal(10,2) NOT NULL default '0.00',
price decimal(10,2) NOT NULL default '0.00',
availability char(3) NOT NULL default 'in',
status text,
type varchar(255) NOT NULL default '',
productsort varchar(255) NOT NULL default 'Ink',
category varchar(255) NOT NULL default 'Ink',
view char(3) NOT NULL default 'on',
PRIMARY KEY (productid),
FULLTEXT KEY brand (brand)
) TYPE=MyISAM;
What i'm unsure of is where to start exactly, the sql needs to first check sales_status.status, where this is pending use the sales_status.orderid to check salesproducts.orderid, use sales_products.productid to find details such as products.code and products.brand.
I can see the logic but i'm not used to sql that is this complex, if anyone could give me any pointers it would be much appreciated.
Thanks.