0

我一直在做一个项目,但我已经到了卡住的地步。我有一个数据库,其中包含一些机器的工作状态。状态的值从 1 到 5。我需要能够根据该 Mahcine 数据库中出现的值在网页中为每台机器显示不同的图像。我在如何做到这一点上画了一个很大的空白。我使用的是 MySQL 数据库,一切都是用 PHP 编写的。

基本上就是这个。如果机器的状态值为 1,则它显示绿色图像。如果值为 2,那么它将是黄色的,依此类推。. .

希望大家能帮忙

4

3 回答 3

0

不要使用 img 标签,而是创建一个 div,您可以为其应用与机器状态值相同的样式类

  <div class="machine status<?php echo $status;?>" ></div>

现在在你的 CSS 中,

.status1{
    background-image:url(red.jpg);
}

.status2{
    background-image:url(green.jpg);
}

.status3{
    background-image:url(jpg.jpg);
}

.machine{
  width:50px;
  height:50px;
}
于 2012-08-04T08:41:46.997 回答
0

你可以尝试这样的事情:

// 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" />'
    }
}
于 2012-08-04T08:20:53.157 回答
0
 Ok you can't display multiple images within a image/jpeg page...

  You're telling the browser that the page is image/jpeg (in other words, the page is     AN IMAGE) but you're echoing out multiple image data

You should rather use the gallery page to show all images like this:

<?php
// $images = result from database of all image rows
foreach ($images as $img) echo '<img src="img.php?id='.$img["id"].'">';
?>

and in img.php:

 // Load the image data for id in $_GET['id'];
header("Content-type: image/jpeg");
echo $data;
于 2013-02-07T09:47:26.657 回答