sanchez77 Posted August 15, 2009 Share Posted August 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/ Share on other sites More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 What does $row['estreturn'] contain? Is it a UNIX Timestamp (eg 1250379582) or a date (dd/mm/yy) Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899127 Share on other sites More sharing options...
sanchez77 Posted August 15, 2009 Author Share Posted August 15, 2009 it a date dd/mm/yyyy Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899142 Share on other sites More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 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> Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899152 Share on other sites More sharing options...
sanchez77 Posted August 15, 2009 Author Share Posted August 15, 2009 right on, thanks so much Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899159 Share on other sites More sharing options...
sanchez77 Posted August 15, 2009 Author Share Posted August 15, 2009 actually, it never changes to the other color. Did I miss something? Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899161 Share on other sites More sharing options...
sanchez77 Posted August 16, 2009 Author Share Posted August 16, 2009 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>"; Link to comment https://forums.phpfreaks.com/topic/170451-change-a-return-variable-a-different-color/#findComment-899526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.