Q:

PHP/MySQL - Calculate Total for each Reservation

I've got a Reservation application, and I'd like to calculate the total number of meals needed by reservations date span.
My database has fields:
$name - Person reserving
$chkin - Check in date (DATE yyyy-mm-dd)
$chkout - Check out date (DATE yyyy-mm-dd)
$guests - Number of people in group
$meal - Eating meals (Yes/No)

So for each reservation I have:
// Days of Stay
$days = (strtotime($chkout) - strtotime($chkin)) / (60 * 60 * 24);

What I'm not sure of is how to do the calculation for each reservation in the database.
My calculation for each reservation would be something like:
$days * $guests

I would appreciate advice on this query... I'm trying to give a snapshot of how many meals will be need to be prepared for a given month, weeekend, etc. 
Thank you!

A:

You can use the MYSQL date diff to achieve a count of the days, then this can be multiplied by the number of guests. Finally you will need to select a date range for this search. Below are the basics or the MYSQL needed in order to get these values. This should put you on the right track to achieving what you want.
SELECT DATEDIFF(a.chkout,a.chkin) * a.guests as meals
FROM table as a 
WHERE a.chkin > '0000-00-00' AND a.chkout < '0000-00-00

I have tested this with a table of mine and it appears to be working correctly, however, without much data I can only test lightly. If you have any issues, leave a comment and I will try to help further.
http://www.w3schools.com/sql/func_datediff.asp

