0

I want to develop a simple website, It consists of a search form (text input and submit button) which are used to fetch data from a database. Under the form, i make some "map" using div tag that each of div tag represent location. If data was found, one of the div tag that represent the location of we've search before will change the style background-color.

here is my 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>

My question is what should i use to implement this?

4

1 回答 1

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 是您必须在找到时分配布尔值的变量。

于 2013-10-27T04:12:39.173 回答