chenci - 2012-03-01 20:22:08
i'm working on a automated script to send mails at 10am (using cron job) to a series of companies' mails stored in my database. I have the main idea, but i don't know to start. Basically i'm stuck in those last items since i'm still learning. These are the 3 tables i have
Table company: id, company_name company_mail
Table log: id, company_id, plate_id, buy_date, ticket_id
Table menu: id, plate_name, plate_price, company_id
This is what i want to do:
1) I have to select all the row from 14pm of the day before to 10am of today with this code
SELECT * from log WHERE buydate BETWEEN date_add(date_sub(curdate(), interval 1 day), interval 14 hour) and date_add(curdate(), interval 10 hour)
2) Select all the companies ids, find repeated ones and group them together.
3) Populate a table with the information based on the company id and their plates
ie: Company_id 1: 3rows (containing plate_id 1,2,3). Company_id 2: 1row (containing plate_id 4)
4) Cross reference plate_id in plate table to show plate_name, plate_price in the table above (instead of plate_ids), send mail to each company with their corresponding information. Thanks