0

could someone help me, i need a php statement that will display an image if an sql record is created within the last week.

My website has a profile page setup and im look to display a new icon on all the latest records

i have a date stamp field on my database called date

can anyone assist

Thanks

Craig
  • 773
  • 2
  • 7
  • 10

2 Answers2

1

this is basically the same as Check if mySQL record added in the last x seconds

$stmt = "SELECT * FROM yourtable WHERE `date` > (now() - interval 7 DAY)";
$result=mysql_query($stmt);
foreach($result as $rec){
    echo "<img src=\"yourimage.jpg\" />";
    //do some more stuff with the mysql result if required
} 
Community
  • 1
  • 1
Gryphius
  • 75,626
  • 6
  • 48
  • 54
  • im not looking to query the database, i have a query that outputs what i require. I need a PHP statement that says something like if created within 7 days display image? – Craig Jun 19 '11 at 09:53
  • added a php example (which assumes you have a existing mysql connection, eg, mysql_connect(.....) mysql_select_db(....) ..... this will display an image for EACH record created within the last 7 days, not sure if that is what you want – Gryphius Jun 19 '11 at 09:55
  • @Craig Nicholls: if you're `not looking to query the database` why the you even mentioned mysql in your question? Remove everything about db in your question, so we know what you actually meant. – zerkms Jun 19 '11 at 10:12
0
if ( (strtotime($row['date'])+7*86400)>time() )
  echo "<img src=\"new.jpg\" alt=\"new\" />";
Gerben
  • 16,747
  • 6
  • 37
  • 56