...

View Full Version : Select DATE help



Kal
06-22-2006, 03:30 PM
Hi,

how would i write a select statement, where i only want to retrieve the records where the "startdate" (held in DB) is less than 7 days old from the current date.

thanks in adavance.

lansing
06-22-2006, 03:34 PM
This will work...just modify it to meet your db & other query requirments.
$sql = mysql_query("SELECT * FROM table WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= date_field");

Kal
06-22-2006, 03:40 PM
i'm getting an error, the code i have is below.

<?php

require ('database3.php');

$sql = mysql_query("SELECT * FROM monksc.news WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= startDate");

$result = mysql_query ($sql) or die (mysql_error());

if (mysql_num_rows($result)>0)

{

while($row=mysql_fetch_array($result))

{

print $row['id'];

}

}

?>

lansing
06-22-2006, 03:46 PM
i'm getting an error, the code i have is below.

<?php

require ('database3.php');

$sql = mysql_query("SELECT * FROM monksc.news WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= startDate");

$result = mysql_query ($sql) or die (mysql_error());

if (mysql_num_rows($result)>0)

{

while($row=mysql_fetch_array($result))

{

print $row['id'];

}

}

?>

What is your error?

Philipp
06-22-2006, 03:51 PM
i'm getting an error, the code i have is below.
which error?

Kal
06-22-2006, 03:53 PM
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1

Kal
06-22-2006, 04:11 PM
i've sorted it now, thanks for your help. i had "mysql_query" written before the select statement

guelphdad
06-22-2006, 04:17 PM
It always helps to actually list the error you get when asking for help. ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum