Jump to content

Problem with changing font color after certain time


badeand
 Share

Recommended Posts

Hi people ;)

 

I'm trying to show all my data in my database, and I'm trying to make the font color change after 7 days to yellow and after 14 days it should show up red. But it does not work, could someone see any error in the code?

 

It turns up green all the time..

 

 

 while($row = mysql_fetch_array($result)) {

    $postTime = $row['date'];
    $thisTime = time();
    $timeDiff = $thisTime-$postTime;

    if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7]
      $color = '#D1180A';
    } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14]
      $color = '#D1B30A';
    } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14]
      $color = '#08C90F';
    }

    echo '<tr style="color: '.$color.';">';

    echo '<td>'. $row['id'] .'</td>';

    echo '<td>'. date("d.m.y", strtotime($row["date"])) .'	</td>';

    echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>';
  
    echo '<td>'. $row['Telefon'] .'</td>';

    echo '<td>'. $row['Emne'] .'</td>';

    echo '</tr>';

  }

  echo '</table>';

 

 

 

Link to comment
Share on other sites

 

This is the value of thoose variables

 

2011-01-01 16:02:42

1295019624

1295017613

 

... and there lies the problem. 2011-01-01 16:02:42 is a date/time while 1295019624 is a timestamp. you can't perform addition/subtraction on these 2 values without converting one type to the other. you can use strtotime() to convert a date/time to a timestamp.

 

But on the other hand, The Little Guy has a possibly simpler solution.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.