Jump to content

change a return variable a different color


sanchez77

Recommended Posts

Hi,

 

I just have to say, love PHP. But my question/problem is how do you take the value lockersmaster.estreturn and date now and if the estreturn is before today, then show the value in red, if the estreturn is after today, then show the value in blue.

 

My code below

$result = mysql_query("SELECT lockers.datein, lockersmaster.estreturn, customer.fname, customer.lname, customer.contactno FROM lockers, lockersmaster, customer WHERE lockers.masterid = lockersmaster.id AND customer.lmasterid = lockersmaster.id");


echo "<table cellpadding='4' cellspacing='4'><tr>
<th>Date In</th>

<th>Estimate Return Date</th>
<th>First Name</th>
<th>Last Name</th>
<th>Contact No.</th>

</tr>";while($row = mysql_fetch_array($result))
  {

  echo "<tr><td> " . $row['datein'] . "</td><td> " . $row['estreturn'] . "</td><td> " . $row['fname'] . "</td><td> " . $row['lname'] . "</td><td> " . $row['contactno'] . "</td><tr>";

  }
echo "</table>";

 

I tried using case but i just couldn't figure it out. Any help is appreciate it.

 

Thanks and Cheers,

Sanchez

Change

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

 

to

while($row = mysql_fetch_array($result))
  {
    list($d, $m, $y) = explode('/', $row['estreturn']);
    $color = strtotime(sprintf('%s/%s/%s', $m, $d, $y) > time()) ? '#00F' : '#F00';

 

Now change

<td> " . $row['estreturn'] . "</td>

 

to

<td style=\"color:$color\"> " . $row['estreturn'] . "</td>

Here is my latest code, the value is blue, but it doesn't change regardless of the date value in estreturn.

 

$result = mysql_query("SELECT lockers.lockerno, lockers.datein, lockersmaster.estreturn, customer.fname, customer.lname, customer.contactno FROM lockers, lockersmaster, customer WHERE lockers.masterid = lockersmaster.id AND customer.lmasterid = lockersmaster.id ORDER BY lockers.lockerno");

echo "<table cellpadding='4' cellspacing='4'><tr>
<th>Locker No.</th></br>
<th>Date In</th>
<th>Estimate Return Date</th>
<th>First Name</th>
<th>Last Name</th>
<th>Contact No.</th>

</tr>";while($row = mysql_fetch_array($result))
  {
    list($d, $m, $y) = explode('/', $row['estreturn']);
    $color = strtotime(sprintf('%s/%s/%s', $m, $d, $y) > time()) ? '#00F' : '#F00';

  echo "<tr><td>" . $row['lockerno'] . "</td><td> " . $row['datein'] . "</td><td style=\"color:$color\"> " . $row['estreturn'] . "</td><td> " . $row['fname'] . "</td><td> " . $row['lname'] . "</td><td> " . $row['contactno'] . "</td></tr>";

  }
echo "</table>";

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.