Solved

Queuing system help

Posted on 2011-02-15
3
387 Views
Last Modified: 2012-05-11
I'm trying to build a kind of queuing table. We are offering items for sale on a daily basis, kind of like woot.com. It is called Daily QuickDeals. Now, I need a script to go through all the records in linv_quick_deals to determine:

1

Is the product not sold out

2

has it not been listed as a QuickDeal in the last 2 days

And if it meets the above criteria, return the inventory_id so I can insert a record into linv_todays_deal with today's date and the inventory_id.

The below isn't working as I expect because it keeps putting inventory_id 1 in when it is sold out.

I'm thinking that I may have a bad design. Should I just either, move the sold_out column to the linv_quick_deals table or remove the record from the linv_quick_deals table when it is sold out?

Any ideas or suggestions will be appreciated.

SELECT `inventory_id` 
FROM   linv_quick_deals i 
WHERE  `inventory_id` NOT IN (SELECT d.`inventory_id` 
                              FROM `linv_todays_deal` d
                              WHERE d.`inventory_id` = i.`inventory_id` 
                              AND   d.`sold_out` <> 0
                              AND   DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= d.`deal_date`)

Open in new window

Data:
CREATE TABLE `linv_todays_deal` (
	`deal_id` INT(10) NOT NULL AUTO_INCREMENT,
	`inventory_id` INT(10) NOT NULL DEFAULT '0',
	`deal_date` DATE NULL DEFAULT NULL,
	`sold_out` TINYINT(4) NULL DEFAULT '1',
	PRIMARY KEY (`deal_id`),
	INDEX `idx_inventory_id` (`inventory_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT;

deal_id 	inventory_id 	deal_date 	sold_out
1 		2 		2011-02-14 	1
2 		1 		2011-02-10 	0


CREATE TABLE `linv_quick_deals` (
	`inventory_id` INT(10) NOT NULL AUTO_INCREMENT,
	`user_id` INT(11) NOT NULL,
	`title` VARCHAR(50) NOT NULL COLLATE 'utf8_unicode_ci',
	`description` TEXT NOT NULL COLLATE 'utf8_unicode_ci',
	`attributes` TEXT NOT NULL COLLATE 'utf8_unicode_ci',
	`order_link` VARCHAR(500) NOT NULL COLLATE 'utf8_unicode_ci',
	`image_link` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
	PRIMARY KEY (`inventory_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT;

inventory_id 	user_id title 	description 	attributes 	order_link 	image_link
1 		23 	Item 1 	<SNIP>  	<SNIP> 		<SNIP>		<SNIP>
2 		23 	Item 2 	<SNIP>		<SNIP>		<SNIP>		<SNIP>

Open in new window

0
Comment
Question by:EddieShipman
3 Comments
 
LVL 26

Accepted Solution

by:
jar3817 earned 400 total points
ID: 34897016
Your linv_quick_deals table doesn't have an "out of stock" column, so can't select products from that table based on whether they're in stock or not.
0
 
LVL 6

Assisted Solution

by:Ferrosti
Ferrosti earned 100 total points
ID: 34897231
Usually one would go for an item_master table and an item_stock table.
In lineitem one would have itemdetails, while stockitem holds information about reservation, quantity, qty_threshold etc.
Problem is that in case of phone calls an agent might tell the customer of a valid stock and two minutes later he could not book it to the customers order. For this case one would reserve an item as soon as a customer agent got its record open.
0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 34901519
Decided to put the sold_out column in the linv_quick_deals table
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now