Hi all,
I currently have a table named orders in a mySQL DB. The table has a column named order_id. Here is the table structure:
CREATE TABLE orders (
order_id int(10) unsigned NOT NULL auto_increment,
customer_id int(10) NOT NULL default '0',
movie_id varchar(5) NOT NULL default '',
movie_title varchar(50) NOT NULL default '',
movie_current_price varchar(10) NOT NULL default '',
qty char(3) NOT NULL default '',
order_date date NOT NULL default '0000-00-00',
processed char(1) NOT NULL default '',
PRIMARY KEY (order_id),
UNIQUE KEY order_id (order_id)
) TYPE=MyISAM;
At the moment when i add an order it obviously auto indexes the order_id row with a unique number.
Now for the question. What if a person orders two or more items. Currently the order gets added with a new table row even if the order is from the same client on the same day.
Here is the script that adds it to the DB:
$result_2 = mysql_query("insert into orders(order_id, customer_id, movie_id, movie_title, movie_current_price, qty, order_date)
values ('NULL', '" . $_SESSION['customer_id'] . "', '$movie_id', '$movie_title', '$movie_current_price', '$qty', '" . date('Ymd') . "')");
What do i need to add to my order table or script to allow the order_id column to insert the same order_id if the client has ordered at that same time.