Jump to content

Text colour depending on query


tommy2shoes

Recommended Posts

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

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

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?

 

 

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.