I have two tables in a Mysql database.
PACKAGES:
ID (auto_increment)
CATEGORY (INT)
NAME (VARCHAR)
EXPIRY (VARCHAR)
VISIBLE (TINYINT)
EXAMPLE:
1 | 1 | Package AAA_1 | INTERVAL 7 DAY | 1
2 | 2 | Package BBB_1 | INTERVAL 1 YEAR | 1
3 | 1 | Packaga AAA_2 | INTERVAL 14 DAY | 1
SUBSCRIPTIONS:
id (auto_increment)
id_user (INT)
id_package (INT) // It points to packages.id
date (DATETIME)
EXAMPLE:
1 | 1 | 1 | 2012-01-06 00:04:18
My problem is that a sigle user can have more subscriptions for the same package (because when a subscription expiry there will be a new subscription and I need to track all the previous subscription to know the “Story” of each user)
Now, I have to create a query to extract all the packages (where packages.visible=1 and ORDER BY packages.category) and
CHECK
What is the real expiration of that user package.
as you see I have subscriptions.date (it is the date when the user does the subscription), then i have to add at this date the packages.expiry to know the DATE of the real expiration. Obviously I ONLY have to add subscription.date + package.expiry to the LAST subscription the user made of that specific package.
EDIT:
Obviously I have to pass to this query the ID of the user I would like to check.
This select statement will give you the information you need, but because the package expiry field appears to be free-form text I don’t think there’s a way to add it to the last subscription date.