Jump to content

help with using IF and ELSE


murdo

Recommended Posts

ok i have a date output from a simple SQL database....

 

If "year" part of the date doesn't match, I want a standard message. if it does match, I want to echo the full date...

 

here is what I am using:

 

<?php
$year=date("Y");
if ($year=="2008")
  echo "N/A"; 
else
  echo "$date"; 
?>

 

All my dates in the database are 2008.. however on the page, I am getting the  $date  echo  instead of  "N/A"

 

am I doing something wrong??

Link to comment
https://forums.phpfreaks.com/topic/82103-help-with-using-if-and-else/
Share on other sites

ahhhhh i see where you are coming from! duh!!

 

So I use this:

 

$query="SELECT *, DATE_FORMAT(date,'%D %M %Y') as date2 FROM datestable

and

$date=mysql_result($result,$i,"date2");

 

so to show the date from the databse in my page, i do  <? echo $date; ?> but how do I condition that so if the year isn't 2008 it doesn't show??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.