Good day all:
I need to search my db table for all services called "oil change" which where inserted 85 days ago (based on an inserted date column in the table) and display those results. Here's what I have:
Mysql Table
id (auto)
servicearea
carid
customerid
dateofservice
An example of a row and its content is:
id=1
servicearea=oil change
carid=dg5632
customerid=mb6524
dateofservice=2011-01-15
Currently, I'm using a smilar code (see below) to pull and display from this table a count down to an end of a number of days (say, 90 days) left to a future date based on that specified number of days.
So essentially, if my date of service is 2011-01-15 and my $limit value is 90 days, the code performs a search in the table for records which have a servicearea value of "oil change" and using the date of service and the $limit to thus determines how many days are left --as of today, until those 90 days expire.
The code for the above described task is as follows:
$get_swork = "select servicearea, date, customerid, clientID from servicesrendered where servicearea=' Oil Change ' and clientID = '$trimmed' order by id desc limit 1";//$trimmed is valued as the a passed carid as a variable to the code
$get_swork_res = mysql_query($get_swork);
if (mysql_num_rows($get_swork_res) > 0)
{
while ( $swork_info = mysql_fetch_array($get_swork_res))
{
$servicearea = $swork_info['servicearea'];
$date = $swork_info['date'];
$customerid = $swork_info['customerid'];
$clientID = $swork_info['clientID'];
$space = " ";
//$lastservicearea = $servicearea.$space.' on '.$date;
//echo $date;
//echo $servicearea;
//echo $customerid;
}
}
else
{
echo " No history of Oil Changes";
}
$timestamp = strtotime($date);
$startDate=$timestamp;
$limit=90;
$z=floor((time() - $startDate)/86400);
$days=$limit-abs($z);
//echo $z;
if ($days > 0) {
echo "<font size=\"4\" color=\"red\">";
echo $days;
echo "</font> days until the next oil change</p>";
}
else
{
$strippeddays=substr($days, 1);// removing the negative symbol from number of days passed
echo "Oil Change is <font size=\"4\" color=\"red\">";
echo $strippeddays;
echo "</font><u> day(s) overdue!!!</u></p>";
}
}
The code above works based on a specified condition in the $get_swork statement (first statement). There is a where clause which provide the statement with a specified variable --a specified clientid (or carid).
For my new task --and the topic of this new thread, I want to search the entire table and only display those records (which could be more than one) that will become due in 5 days from today --basically, displaying on the 85th day from the date of service.
Essentially for this new task, if my date of service is 2011-01-15 and my $limit value is 90 days, I want perform a search in the table for records which have a servicearea value of "oil change" and using the date of service and the limit of 90 days, I want to display all records which 90 days will come to an end in 5 days from the today's date.
My apologizes, as I may have not done a good job explaining --but I hope I did.
Any thoughts on this!
Best
Mossa