更改签入表格的颜色

时间:2017-02-08 00:47:11

标签: php

我想创建一个显示数据库记录的表单 姓名,电子邮件,电话号码和情况,选择后我想改变静音的背景颜色,它取决于价值吗?

 <form method="post">
 <input type="text" name="ID" placeholder="ID">
<input name="set" type="submit">
</form>
 <?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 $ID = isset($_POST['ID']) ? $_POST['ID'] : false;
$connect = mysql_connect('localhost', 'root', '','seminar'); 
mysql_select_db ('seminar'); 
$sql = "SELECT `name`, `del_company`, `phone`, `email`,  ,`situation` FROM   `dele` WHERE ID = $ID";
$res = mysql_query($sql);
 if(! $ID ) {
  die("Could not get data:" . mysql_error());
   } while($row = mysql_fetch_array($res)) {
while($row = mysql_fetch_array($res)) {

 echo "<br><p><b>Surname:  </b></b></b>", $row['name'], "</p>";
echo "<br><p><b>company:  </b></b>", $row['del_company'], "</p>";
echo "<br><p><b>phone:  </b></b></b></b>", $row['phone'], "</p>";
echo "<br><p><b>email:  </b></b></b></b></b>", $row['email'], "</p>";
echo "<br><p><b>expert:  </b><br>", $row['situation'], "</p>";

}

}
else {
  echo "<p>Enter a valid ID above</p>";
}
 mysql_close($connect);

&GT;

1 个答案:

答案 0 :(得分:1)

更改此行

echo "<br><p><b>expert:  </b><br>", $row['situation'], "</p>";

这样的事情:

echo "<br><p class=".$cssClass."><b>expert:  </b><br>", $row['situation'], "</p>";

在此之前,你需要创建一些逻辑,说明situation是什么,然后$cssClass =无论如何。然后为每个类添加一些CSS。

这样的事情:

if ($row['situation'] == "horse") {$cssClass == "blue-color"};
elseif ($row['situation'] == "cow") {$cssClass == "red-color"};
else {$cssClass == "yellow-color"};

然后定义你的CSS:

.blue-color{
background-color:blue;
}

ETC。