murdo Posted December 17, 2007 Share Posted December 17, 2007 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 More sharing options...
lemmin Posted December 17, 2007 Share Posted December 17, 2007 date() gets the current date, which is 2007. You don't have anything from your database query in this conditional statement. Link to comment https://forums.phpfreaks.com/topic/82103-help-with-using-if-and-else/#findComment-417211 Share on other sites More sharing options...
murdo Posted December 17, 2007 Author Share Posted December 17, 2007 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?? Link to comment https://forums.phpfreaks.com/topic/82103-help-with-using-if-and-else/#findComment-417217 Share on other sites More sharing options...
murdo Posted December 17, 2007 Author Share Posted December 17, 2007 never mind... problem solved... Link to comment https://forums.phpfreaks.com/topic/82103-help-with-using-if-and-else/#findComment-417233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.