473,729 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql query changing font color

2 New Member
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
  2.  
  3.     include 'admin/config.php';
  4.     include 'admin/opendb.php';
  5.  
  6.     $query  = "SELECT druid FROM oth_recruitment";
  7.     $result = mysql_query($query);
  8.  
  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
3 8321
ronverdonk
4,258 Recognized Expert Specialist
$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.
[php]
while ($row = mysql_fetch_ass oc($query)) {
if ($row['druid'] == 'Open')
echo "<font color=\"#00FF00 \">Open</font>";
else
echo "<font color=\"#FF0000 \">Closed</font>";
//
// process other columns in the row
//
}
[/php]

Ronald
Feb 10 '08 #2
petrakid
2 New Member
thanks, I had to change $query to $result - but other than that, it works perfectly.
Feb 11 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
Glad it does. See ya.

Ronald
Feb 11 '08 #4

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

Similar topics

6
1037
by: phpguy | last post by:
Hi people im making an online booking system as a final year project in my university i get this error which i cannot seem to fix ! Here is my code: PART 1 ********************************************************* #connect to sql $connect=@mysql_connect("localhost","root","") or die("Err:Conn");
1
1918
by: no-email | last post by:
Hi, Below is a bunch of programs to demo the basic sql commands. Suggestions on possible improvements will be appreciated. <?php // mysql-demo.php include ("connectdb.php"); $setSQL="SET FOREIGN_KEY_CHECKS=0"; $dropSQL="DROP TABLE IF EXISTS temp";
1
3213
by: automation | last post by:
There is a truncation error of my Web Application using PHP 5.04, MySQL 5.022, and HTML(IE 6.0) whereby the MySQL Result Set is being truncated on the HTML page, even though the CSS Div Page Height is set to 'auto' which is supposed to grow the HTML page height to the size necessary to display the contents within the page. The query count is correct, but the MySQL Result Set is being truncated on the html page. This happens for MySQL Results on...
3
3108
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php, I use: $query2 = "SELECT id, order_no, price, count(item_no) as count from production where item_no = '27714";
7
2503
by: dongletran06 | last post by:
Hi, Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input text" are successfully adding data to mysql. I just try first using the month as drop down. The month data type I used in mysql database is varchar. Im new in PHP please help me. Thanks <?php /* Created on: 10/12/2006 */ ?> <html> <body> <?php...
3
1288
by: alisonjane | last post by:
Hi, First, I apologize, but I am a biologist not a programmer! Second, I made a web-based scheduling system in mysql. It works great but I need to generate a report by specifying a range of dates on another webpage. I made the query to give me the columns I want, but I don't know how to create the front-end page on which I would like select the range of dates to show me. Here is the query that returns ALL records: <? // script to...
11
4281
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP table that displays all records in my database on this same page. This too works fine. I have my table set up so that there is a 7th field, called "rid" to act as a "record id" or unique identifying field. This is primary and auto-incremented. There...
39
5864
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
70
5393
mideastgirl
by: mideastgirl | last post by:
I have recently been working on a website for an honors association, and have a lot of difficulty but have found help from those on this site. I would like to see if I can get some more help on a different issue than what I was initially having. I am working on storing data collected from a form on my website. I would like the information to be stored into MySQL once entered by users. I have googled this question and have tried multiple...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.