Page 1 of 1
If date
Posted: Sat Sep 20, 2003 8:42 am
by jamrop
Hi
I have a database that has a list of films record that a member puts in. When they add the record a date is stored in the database. Now want i am trying to do is, display the films a member has added, but if a record is a week old to display a button
so e.g.
Code: Select all
<?php
if (TODAY(now()) - (TODAY($date)) <= 7){
echo "<td width="5%" bgcolor="$row_color" valign="middle" align="middle">
<a href='delete.php?advert_id=$advert_id&check=$member_id&type=ad '><img src='../classfied/cancel.gif' width="30" height="23" border="0"></a> </td>\n";}
?>
$date = the date a member added a film
I know that the if statement is wrong, but how would i go around so it understands the date now, and the date the film record was stored,.
Many thanks
jamie
Posted: Sat Sep 20, 2003 9:34 am
by volka
e.g.
Code: Select all
<?php
$now = time();
$dummyRecordset = array(
"20 September 2003",
"19 September 2003",
"1 September 2003"
);
foreach($dummyRecordset as $row)
{
$date = strtotime($row);
if ($now - $date <= (7*86400)) // a day has ~86400 seconds
echo '!';
else
echo "#";
echo $row, " \n";
}
?>
if your databse supports it and you want to stay with that database you can let it do the work for you, e.g. for mysql you might use something like
Code: Select all
SELECT ...fields you need..., (insertDate < Now() - Interval 7 day ) as oldMovie FROM movies
The records returned will have a field called
oldMovie. If it's value is 0 then it's not an old movie, otherwise it is.
Code: Select all
while( ...fetching a row... )
...
if($row['oldmovie']) echo 'this is an old movie entry';
...
see also:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
Posted: Sat Sep 20, 2003 10:23 am
by jamrop
hey
Thanks for your help, but i am a bit confused of the sql statement you put.
At the moment i have
Code: Select all
select * from movies where member_id = '$member_id' and valid = 1;
that displays all the records
I dont understand where the
Code: Select all
(insertDate < Now() - Interval 7 day ) as oldMovie FROM movies
would go, cause if i put it as
after the valid = 1, it would only display the records that are over a week old, where as i need all the records.
Many thanks
Posted: Sat Sep 20, 2003 11:29 am
by volka
Code: Select all
select *, (insertdate < Now() - Interval 7 day ) as oldMovie from movies where member_id = '$member_id' and valid = 1;
The resultset contains what you select: a set of records/rows each having the fields you've selected.
means: from each recordset select all fields
means: from each recordset select only the field member_id
means: from each recordset select only the field member_id and the value of the function Now()
Code: Select all
select *, (insertdate < Now() - Interval 7 day )
means: from each recordset select all fields and the result of the comparison
Code: Select all
select *, (insertdate < Now() - Interval 7 day ) as oldMovie
means: from each recordset select all fields and the result of the comparison and name this field oldMovie
...
The where-clause determines wether a complete row is in the resultset or not