The first thing to consider is the design of your database tables. Off hand I'd start with something like this:
Note: I'm using sort-of generic datatype names, you'll have to adapt for your particular database.create table section ( sectionId int , sectionName varchar(32) , dateCreated date -- maybe some other fields that describe the section -- status ) create table inventoryItem ( itemId int , itemName varchar(32) , sectionId int , description varchar(255) , photoLocation varchar(255) , dateCreated date , dateLastModified date , status int , price numeric , salePrice numeric NULL )
If you want maximum flexibility for the pricing of your items you'd break out the price from the inventoryItem table and create a table just for the price:
By using this price table you can store a default price for the item (with type = 0 and validFrom/validTo left NULL), and any sale price entered with the type == 1 and appropriate dates for validFrom and validTo.create table itemPrice ( itemId int , price numeric , type int -- 0 for normal, 1 for sale , validFrom date NULL , validTo date NULL )
Now to fetch the items for a section you'd have a query that would look somewhat like this:
where getdate() returns the current date.select s.sectionName , i.itemId , i.itemName -- other inventoryItem columns as needed , p1.price , "sale_price" = p2.price from section s left join inventoryItem i on s.sectionId = i.sectionId left join itemPrice p1 on i.itemId = p1.itemId and p1.type = 0 left outer join itemPrice p2 on p1.itemId = p2.itemId and p2.type = 1 and p2.fromDate < getdate() and p2.toDate > getdate()
This will return the appropriate rows, like this:
itemId price sale_price ---------- ------- ---------- -------------------- ------------------ +-- section 1 1 item 1 24.990000 NU +LL section 1 2 item 2 19.990000 14.9900 +00
Once you have the data fetched it becomes relatively easy to format it for your web page.
Michael
In reply to Re: Managing Inventory Sections with Perl and SQL
by mpeppler
in thread Managing Inventory Sections with Perl and SQL
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |