PDA

View Full Version : Help with SQL Query



Moh
16-02-2009, 05:24 PM
I'm a little bit stuck and confused my self :(

In the database, there's several items which all have time stamps.

Does anyone know how I can find all the items with a time stamp with a range of:



Now and Yesterday
Yesterday and Day before yesterday
Day before yesterday and day before that
Etc..

So in the end, it will give us this result:

16/02/2009: item9, item8, item7
15/02/2009: item6, item5, item4
14/02/2009: item3, item2, item1

Thanks, and plus rep :)


Oh, and so far im using:


$now = time();
$one = strtotime("- 1 day");
$two = strtotime("- 2 day");
$three = strtotime("- 3 day");
$four = strtotime("- 4 day");
$five = strtotime("- 5 day");
$six = strtotime("- 6 day");
$seven = strtotime("- 7 day");

$getone = mysql_query("SELECT * FROM `updates` WHERE `date` > '$one' AND `date` < '$now'");
$gettwo = mysql_query("SELECT * FROM `updates` WHERE `date` > '$one' AND `date` < '$two'");
$getthree = mysql_query("SELECT * FROM `updates` WHERE `date` > '$two' AND `date` < '$three'");
$getfour = mysql_query("SELECT * FROM `updates` WHERE `date` > '$three' AND `date` < '$four'");
$getfive = mysql_query("SELECT * FROM `updates` WHERE `date` > '$four' AND `date` < '$five'");
$getsix = mysql_query("SELECT * FROM `updates` WHERE `date` > '$five' AND `date` < '$six'");
$getseven = mysql_query("SELECT * FROM `updates` WHERE `date` > '$six' AND `date` < '$seven'");

Agnostic Bear
16-02-2009, 06:33 PM
I'm a little bit stuck and confused my self :(

In the database, there's several items which all have time stamps.

Does anyone know how I can find all the items with a time stamp with a range of:



Now and Yesterday
Yesterday and Day before yesterday
Day before yesterday and day before that
Etc..

So in the end, it will give us this result:

16/02/2009: item9, item8, item7
15/02/2009: item6, item5, item4
14/02/2009: item3, item2, item1

Thanks, and plus rep :)


Oh, and so far im using:


$now = time();
$one = strtotime("- 1 day");
$two = strtotime("- 2 day");
$three = strtotime("- 3 day");
$four = strtotime("- 4 day");
$five = strtotime("- 5 day");
$six = strtotime("- 6 day");
$seven = strtotime("- 7 day");

$getone = mysql_query("SELECT * FROM `updates` WHERE `date` > '$one' AND `date` < '$now'");
$gettwo = mysql_query("SELECT * FROM `updates` WHERE `date` > '$one' AND `date` < '$two'");
$getthree = mysql_query("SELECT * FROM `updates` WHERE `date` > '$two' AND `date` < '$three'");
$getfour = mysql_query("SELECT * FROM `updates` WHERE `date` > '$three' AND `date` < '$four'");
$getfive = mysql_query("SELECT * FROM `updates` WHERE `date` > '$four' AND `date` < '$five'");
$getsix = mysql_query("SELECT * FROM `updates` WHERE `date` > '$five' AND `date` < '$six'");
$getseven = mysql_query("SELECT * FROM `updates` WHERE `date` > '$six' AND `date` < '$seven'");


A good idea would be to give us the timestamp type, is it MySQL, UNIX?

Moh
16-02-2009, 08:51 PM
A good idea would be to give us the timestamp type, is it MySQL, UNIX?
Ah sorry, Unix.

Want to hide these adverts? Register an account for free!