我一直在做一个元素,但我遇到了困难。我有一个数据库,其中包含一些机器的工作状态。状态值从 1 到 5。我需要能够根据该 Mahcine 的数据库中显示的值在网页中为每台机器显示不同的图像。我对如何执行此操作一无所知。我使用的是 MySQL 数据库,所有内容都是用 PHP 编写的。
基本上就是这样。如果机器的状态值为 1,则它显示绿色图像。如果该值为 2,则它将是黄色,依此类推。 . .
希望大家帮忙
最佳答案
你可以尝试这样的事情:
// your mysql select, wich contains the machine data.
$query = mysql_query("select the data about machines...");
// you iterate on the result set and fetch each row to $data
while($data = mysql_fetch_array($query))
{
switch($data['machine'])
{
case "machine type 1": // you can put integer values here as well, like case 1:
echo '<img src="first_machine.jpg" alt = "first machine" />'
break;
case "machine type 2":
echo '<img src="second_machine.jpg" alt = "second machine" />'
break;
default: // undefinied
echo '<img src = "undefinied.jpg" alt = "undefinied" />'
}
}
关于php - 根据数据库中的值在 div 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11806998/