I am new to PHP MySQL and jQuery, i am making a service desk form and database, i can input data and display data in a good format. i just need to be able to change color of text dependent on the value in MySQL database; such as status = delayed, in-flight, refueling, take-off, landed, all 5 need to be different colors, such as; Delayed = red, Refuelling = orange, take-off = light green, in-flight = dark green, landed = blue
我是PHP MySQL和jQuery的新手,我正在制作服务台表格和数据库,我可以以良好的格式输入数据和显示数据。我只需要能够根据MySQL数据库中的值更改文本颜色;如状态=延迟,飞行中,加油,起飞,着陆,所有5种需要不同的颜色,如;延迟=红色,加油=橙色,起飞=浅绿色,飞行中=深绿色,着陆=蓝色
is there a way to do this?
有没有办法做到这一点?
2 个解决方案
#1
0
If it's a PHP generated page you can write classes in your css file like:
如果它是PHP生成的页面,您可以在css文件中编写类,如:
.blue {
color: blue;
}
etc...
And then with PHP put the right class based on the value retrieved from MYSQL.
Hope this help.
等等...然后用PHP根据从MYSQL检索的值放置正确的类。希望这有帮助。
#2
0
You should fetch the value from database and store it in a variable like so: $response = DATA FROM DB then you can use switch statement to check the response and set the color accordingly:
您应该从数据库中获取值并将其存储在如下变量中:$ response = DATA FROM DB然后您可以使用switch语句检查响应并相应地设置颜色:
switch ($response)
{
case "delayed":
// maybe frame the element like so
<span class="delayed">Delayed</span>
// or set a class using a variable
$class = "red";
break;
case "in-flight":
<span class="in-flight">Delayed</span>
//or
$class = "orange";
break;
// always good to set a default value
default:
code to be executed if n is different from both delayed and in-flight;
}
if you used the switch statement to set a classname then you can frame your element just below it like so:
如果你使用switch语句来设置一个类名,那么你可以在它下面框架你的元素,如下所示:
<span class="<?php echo $class; ?>">Delayed</span>
then using css
然后用css
.red{
color: red;
}
.orange{
color: orange
}
#1
0
If it's a PHP generated page you can write classes in your css file like:
如果它是PHP生成的页面,您可以在css文件中编写类,如:
.blue {
color: blue;
}
etc...
And then with PHP put the right class based on the value retrieved from MYSQL.
Hope this help.
等等...然后用PHP根据从MYSQL检索的值放置正确的类。希望这有帮助。
#2
0
You should fetch the value from database and store it in a variable like so: $response = DATA FROM DB then you can use switch statement to check the response and set the color accordingly:
您应该从数据库中获取值并将其存储在如下变量中:$ response = DATA FROM DB然后您可以使用switch语句检查响应并相应地设置颜色:
switch ($response)
{
case "delayed":
// maybe frame the element like so
<span class="delayed">Delayed</span>
// or set a class using a variable
$class = "red";
break;
case "in-flight":
<span class="in-flight">Delayed</span>
//or
$class = "orange";
break;
// always good to set a default value
default:
code to be executed if n is different from both delayed and in-flight;
}
if you used the switch statement to set a classname then you can frame your element just below it like so:
如果你使用switch语句来设置一个类名,那么你可以在它下面框架你的元素,如下所示:
<span class="<?php echo $class; ?>">Delayed</span>
then using css
然后用css
.red{
color: red;
}
.orange{
color: orange
}