[SOLVED] query 5 days or more ago

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

[SOLVED] query 5 days or more ago

Post 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'";
Last edited by rsmarsha on Thu May 05, 2005 5:30 am, edited 1 time in total.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

looks like it to me

why not try it?
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Hehe, will do, was just the dateadded< i wasn't sure about, wanted to get confirmation first. :)
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: query 5 days or more ago

Post 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;
}
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Ah :) why the { } round the variables?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Ah ok , thanks for the tips. :)
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

no problem
Post Reply