我想开发一个简单的网站,它包含一个搜索表单(文本输入和提交按钮),用于从数据库中获取数据。在表单下,我使用div标签制作一些“map”,每个div标签代表位置。如果找到数据,则表示我们之前搜索过的位置的div标签之一将更改样式背景颜色。
这是我的HTML
<html>
<head>
<title></title>
</head>
<body>
<div>
<form name='searhThings' method=GET action='<?php $_SERVER['PHP_SELF']; ?>' />
<input type='text' name='idX' />
<input type='submit' value='search' />
</form>
</div>
<div>
<p>Location:
<?php
include 'connection.php';
if ((isset($_GET['submit'])) AND ($_GET['search'] <> "")) {
$data = $_GET['search'];
$result = mysql_query("SELECT * FROM things WHERE ID_X = '$data'");
$row = mysql_fetch_array($result);
if ($row) {
# code...
$id_location = $row['LOCATION'];
echo $id_location;
} else {
# code...
echo "data not found";
}
}
?>
</p>
</div>
<div>
<div id='locationA'></div>
<div id='locationB'></div>
<div id='locationC'></div>
<div id='locationD'></div>
<div id='locationE'></div>
</div>
</body>
</html>
我的问题是我应该用它来实现这个目标?
答案 0 :(得分:0)
您可以根据条件
将类保持为位置div中的活动状态
位置:
if ((isset($_GET['submit'])) AND ($_GET['search'] <> "")) {
$data = $_GET['search'];
$result = mysql_query("SELECT * FROM things WHERE ID_X = '$data'");
$row = mysql_fetch_array($result);
if ($row) {
# code...
$id_location = $row['LOCATION'];
echo $id_location;
} else {
# code...
echo "data not found";
}
}
?>
</p>
</div>
<div>
<div id='locationA' class="<?php if($locationA){ echo 'active'; }?>"></div>
<div id='locationB' class="<?php if($locationB){ echo 'active'; }?>"></div>
<div id='locationC' class="<?php if($locationC){ echo 'active'; }?>"></div>
<div id='locationD' class="<?php if($locationD){ echo 'active'; }?>"></div>
<div id='locationE' class="<?php if($locationE){ echo 'active'; }?>"></div>
</div>
其中$ locationA,$ locationB,$ locationC,$ locationD,$ locationE是必须分配布尔值的变量。