By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

mysql query changing font color

P: 2
I have a table called oth_recruitment

In the table are 10 fields. Each field will have only 1 entry: Open or Closed.

On my website, I have the following code:

Expand|Select|Wrap|Line Numbers
  1.        <?php
  3.     include 'admin/config.php';
  4.     include 'admin/opendb.php';
  6.     $query  = "SELECT druid FROM oth_recruitment";
  7.     $result = mysql_query($query);
  9.         if ($result == 'Open')
  10.         {
  11.             echo "<font color=\"#00FF00\">Open</font>";
  12.         } else
  13.         {
  14.             echo "<font color=\"#FF0000\">Closed</font>";
  15.         }
  16.     ?> 
When the query runs, and it finds "Open" in the field druid, I want word "Open" to show on the webpage, and I want it to be green. When the word "Closed" is found, I want the word "Closed" to show in red. I'm doing something wrong here, obviously, because no matter what I change the value to in the table, it always displays "Closed".
Feb 10 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 4,258
$query only contains the handle to your result set. You have to read or browse through the result set. Since you have 1 column result only you could use mysql_result, but I will show how to read an entire row and how to address the individual columns via an associated (row) array, e.g.
while ($row = mysql_fetch_assoc($query)) {
if ($row['druid'] == 'Open')
echo "<font color=\"#00FF00\">Open</font>";
echo "<font color=\"#FF0000\">Closed</font>";
// process other columns in the row

Feb 10 '08 #2

P: 2
thanks, I had to change $query to $result - but other than that, it works perfectly.
Feb 11 '08 #3

Expert 2.5K+
P: 4,258
Glad it does. See ya.

Feb 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.