Page 1 of 1
[SOLVED] query 5 days or more ago
Posted: Thu May 05, 2005 4:38 am
by rsmarsha
I need to find records 5 with a date of 5 days or more from the current date and remove them.
Would this work to find them?
Code: Select all
//set time
$exp_stamp = time() - 432000;
$expired = date('Y-m-d', $exp_stamp);
$reason = 'No credit update received';
//query
$search = "SELECT * FROM orders WHERE dateadded<'$expired' AND status='Awaiting credit check'";
Posted: Thu May 05, 2005 4:39 am
by malcolmboston
looks like it to me
why not try it?
Posted: Thu May 05, 2005 4:46 am
by rsmarsha
Hehe, will do, was just the dateadded< i wasn't sure about, wanted to get confirmation first.

Re: query 5 days or more ago
Posted: Thu May 05, 2005 5:04 am
by malcolmboston
bored so i thought i would show you how i would write it
Code: Select all
//set time
$exp_stamp = time() - 432000;
$expired = date('Y-m-d', $exp_stamp);
$atatus = "Awaiting credit check";
//query
$query = "SELECT * FROM orders WHERE dateadded < '{$expired}' AND status = '{$status}'";
$result = mysql_query ($query) or die (mysql_error())
$num_rows = mysql_num_rows($result);
if ($num_rows >= 1)
{
// theres a result set
// creat the array or whatever is necessary
}
else
{
// no results
exit;
}
Posted: Thu May 05, 2005 5:13 am
by rsmarsha
Ah

why the { } round the variables?
Posted: Thu May 05, 2005 5:28 am
by malcolmboston
just a different method that i feel more comfortable with as it is easier to spot variables imo, some people use the .'$var'. method. all down to personal preference i suppose
Posted: Thu May 05, 2005 5:30 am
by rsmarsha
Ah ok , thanks for the tips.

Posted: Thu May 05, 2005 5:45 am
by malcolmboston
no problem