tommy2shoes Posted March 31, 2009 Share Posted March 31, 2009 Hi I am writing a database which records activities of various members of staff. There are two tables which matter here: tblStaff (staffid; forename; surname) tblActivity (activityid;staffid;date;text) I can display the results of this OK in date order but would like to amend the text so that it is (for example) greenfor Person A, blue for person B and so on. I would also like the text to be red when it is today's date. I have no idea how to do this so any pointers would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/151907-text-colour-depending-on-query/ Share on other sites More sharing options...
lonewolf217 Posted March 31, 2009 Share Posted March 31, 2009 well how many people / colors are you talking about here I guess the easiest way i can think of would be using a switch statement <?php while($row = mysql_fetch_array($query)) { switch($row['name']) { case 'John': echo "<span style=\"color:green\">".$row['name']."</span>"; break; case 'Mary': echo "<span style=\"color:red\">".$row['name']."</span>"; break; default: echo "<span style=\"color:black\">".$row['name']."</span>"; break; } } For the date part I am not so sure how to determine today's date, but you can take a look at the date() function for ideas Link to comment https://forums.phpfreaks.com/topic/151907-text-colour-depending-on-query/#findComment-797677 Share on other sites More sharing options...
Dtonlinegames Posted March 31, 2009 Share Posted March 31, 2009 Well to get todays date you can use SQL mysql_query("select now()")or die(mysql_error()); And just assign that to a variable. Link to comment https://forums.phpfreaks.com/topic/151907-text-colour-depending-on-query/#findComment-797729 Share on other sites More sharing options...
tommy2shoes Posted April 1, 2009 Author Share Posted April 1, 2009 I'll try that. Using a slightly different set of tables the code I use to give a list is: <table border="0"> <tr> <td>articleid</td> <td>journalid</td> <td>date</td> <td>note</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['articleid']; ?></td> <td><?php echo $row_Recordset1['journalid']; ?></td> <td><?php echo $row_Recordset1['date']; ?></td> <td><?php echo $row_Recordset1['note']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> If I wanted, say, red if articleid = 1, orange if articleid = 2; yellow if articleid = 3; green if articleid = 4 etc, how would I put this into my code using the switch statement? Link to comment https://forums.phpfreaks.com/topic/151907-text-colour-depending-on-query/#findComment-798723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.