jeff5656 Posted October 15, 2008 Share Posted October 15, 2008 The following code makes the background color turn red if the date is today or earlier (i.e. past due). HOW do I make the background color NOT turn red if the date field is BLANK? The date field is rcf1. <?php $curr_date = date ("Y-m-d"); $today = strtotime ($curr_date); $whencheck = strtotime ($row['rcf1']); if ($row['rcf1'] <= $curr_date) { echo "<td bgcolor='#FF0033'>"; echo "<font color='#FFFFFF'>"; echo "<b>"; } else { echo "<td bgcolor='#FFFFFF'>"; } ?> <?php echo $row['rcf1'];?> Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/ Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 change: echo "<td bgcolor='#FF0033'>"; to: echo "<td>"; Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666432 Share on other sites More sharing options...
DarkWater Posted October 15, 2008 Share Posted October 15, 2008 change: echo "<td bgcolor='#FF0033'>"; to: echo "<td>"; That would completely remove any coloring. Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666436 Share on other sites More sharing options...
jeff5656 Posted October 15, 2008 Author Share Posted October 15, 2008 . That would completely remove any coloring True. What I want is BG color red if it is today or past due date. If the field is blank, my code makes the color red but I do not want a blank field to give the red BG color. Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666437 Share on other sites More sharing options...
prexep Posted October 15, 2008 Share Posted October 15, 2008 Make a elseif checking to see if it's empty(). <?php $curr_date = date ("Y-m-d"); $today = strtotime ($curr_date); $whencheck = strtotime ($row['rcf1']); if ($row['rcf1'] <= $curr_date) { echo "<td bgcolor='#FF0033'>"; echo "<font color='#FFFFFF'>"; echo "<b>"; } elseif(empty($row['rcf1'])) { echo "<td bgcolor='#FFFFFF'>"; } else { echo "<td bgcolor='#FFFFFF'>"; } ?> <?php echo $row['rcf1'];?> Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666441 Share on other sites More sharing options...
DarkWater Posted October 15, 2008 Share Posted October 15, 2008 Nope, still wrong. You'd need the empty() check first because otherwise it's always going to fulfill the first condition. I'd actually prefer to do it this way: <?php $curr_date = date ("Y-m-d"); $today = strtotime ($curr_date); $whencheck = strtotime ($row['rcf1']); if (!(empty($row['rcf1'])) && ($row['rcf1'] <= $curr_date)) { echo "<td bgcolor='#FF0033'>"; echo "<font color='#FFFFFF'>"; echo "<b>"; } else { echo "<td bgcolor='#FFFFFF'>"; } ?> <?php echo $row['rcf1'];?> Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666448 Share on other sites More sharing options...
jeff5656 Posted October 15, 2008 Author Share Posted October 15, 2008 Ok I have an update, I found out that the fields that are blank actually have a date of 1969. So how would I do the above code so that if it's between now and, say, 4 years ago make it red, otherwise don't make it red? I could NOT figure out how to do this. I tried with an if AND statement and used old_date to be ("y")-4, but I couldn't get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666478 Share on other sites More sharing options...
prexep Posted October 15, 2008 Share Posted October 15, 2008 Add a greater or less than expression. Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666479 Share on other sites More sharing options...
jeff5656 Posted October 15, 2008 Author Share Posted October 15, 2008 I figured it out: if ($row['check_date2'] <= $curr_date && $row['check_date2'] >= $old_date) Quote Link to comment https://forums.phpfreaks.com/topic/128593-a-date-question-if-field-is-blank/#findComment-666484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.