I’m setting up a new database scheme for an auction website and trying to send email to users for when specific items they’re looking for are posted. I have three tables:
auctions
-each item that is posted by user gets an entry here with the title, a googleID, current bid, etc.
alerts
-these are setup by users and they include the googleID of the item they’re looking for, their user ID, an enabled boolean and a timestamp
notifications
-this keeps track of which users have been alerted about which items so that we don’t alert the same user about the same item every time our cron.php is run. Includes alert ID and the auction ID
So I’m trying to create a query that Selects the following:
- alert is enabled in
alertstable - googleID in
alertstable matches googleID inauctionstable - auction is not closed in
auctionstable - alert ID & auction ID in
notificationstable are not on the same row (this is the part I’m having trouble with. I need to make sure a single auction ID can have multiple alerts sent out for it, but never the same auction to any user multiple times)
This is the query I have so far, but I’m really stuck on that last part and I’ve looked everywhere I can think of for this. Hopefully I’ve explained myself enough, let me know if any clarification would help and thanks in advance!
$sql = "SELECT a.user, b.id, b.title, b.googleimg, b.authors
FROM alerts a, auctions b, notifications c
WHERE a.googleID = b.googleid AND a.enabled = 'y' AND b.closed = 0 AND ????";
How about –