PHP搜索MySQL表与下拉框

时间:2015-03-03 10:14:45

标签: php mysql html-table

我正在尝试创建一个搜索数据库的县字段的搜索框。如果条件匹配,则记录将显示在表格中。我在下拉框中有不同的县,但是当我点击记录时表格没有变化。任何帮助将不胜感激!

<?php
require_once("includes/session.php");
include_once("includes/masterinclude.php");

$preferences = getPreferences();
$category = "";
$attribute1 = ""; $attribute2 = ""; $attriute3 = ""; $attribute4 = "";
$top_level="0";

$name = $_GET['members'];
$information = getInformationPage($name);
$infopagename=$information->IN_NAME;
//meta data for information pages now taken from the information table
$pageTitle = $information->IN_NAME . html_entity_decode($information->IN_TITLE);
$pageMetaDescription = html_entity_decode($information->IN_META_DESC);
$pageMetaKeywords = html_entity_decode($information->IN_META_KEYWORDS);
$pageCustomHead = html_entity_decode($information->IN_CUSTOM_HEAD, ENT_QUOTES);

//initialise screen fields
$selected_member = "";
$id = "";
$username = ""; $username_original = "";
$password = ""; $password_original = "";
$password_test = "";
$title = "MR"; $first_name = ""; $last_name = ""; $company_name = "";
$address1 = ""; $address2 = ""; $town = ""; $county = ""; $country = ""; $postcode = ""; $phone = ""; $mobile = ""; $email = "";
$member_confirmed = "N";
$ast_first = 0; $ast_last = 0; $ast_company = 0; $ast_add1 = 0; $ast_add2 = 0; $ast_town = 0; $ast_county = 0; $ast_country = 0; $ast_post = 0; $ast_phone = 0;
$ast_mobile = 0; $ast_email = 0;
$ast_user = 0; $ast_pass = 0; $ast_passconf = 0;

$members = Get_All_Members("ALL");
$_GET['searchdata'] = $_POST['SEARCH_DATA']; $_GET['searchmember'] = $_POST['MEMBER'];

include_once("includes/header.php");
?>

<!-- start: Page header / Breadcrumbs -->

<div id="breadcrumbs">
    <div class="container">
        <div class="breadcrumbs"> 
        <a href="/">Home</a><i class="icon-angle-right"></i>Stockists
        </div>
    </div>
</div>

<!-- end: Page header / Breadcrumbs -->


<!-- start: Container -->
<div id="container">
    <div class="container">
        <div class="row-fluid">

        <form class="form-horizontal form-box" role="form" name="enter_thumb" action="/stockists.php" enctype="multipart/form-data" method="post" onsubmit="return validate_discount_table();"> 

        <!-- start: Page section -->
        <section class="span12">
            <div class="row-fluid shop-result">
                <div class="inner darken clearfix">
                <h1>Stockists</h1>
                </div>
            </div>



            <div class="row-fluid">

            <div class="form-group">
                    <label class="col-lg-4">Search County: </label>
                <div class="col-lg-4">
                    <Input class="form-control" name="SEARCH_DATA" type="text" size="72" value="<?php echo isset($_POST['SEARCH_DATA']) ? $_POST['SEARCH_DATA'] : "" ?>"/>
                </div>

                <div class="col-lg-4">
                    <Input name="SEARCH" type="submit" value="search" class="btn btn-primary"/>
                </div>

                <div class="col-lg-4">
                    <select name="search_results" id="jumpMenu" onchange="MM_jumpMenu('parent',this,1)">
                        <option value="#">Choose from...</option>
                            <?php
                            if (isset($_POST['SEARCH_DATA'])){
                            $members = Search_member($_POST['SEARCH_DATA']);
                            foreach($members as $m){
                            if(isset($_POST['SELECTED_MEMBER']) and $_POST['SELECTED_MEMBER'] == $m->MB_COUNTY){
                            $selected = "selected";
                            }else{
                            $selected = "";
                            }
                            echo "<option value=\"/stockists.php?searchdata=" . $_POST['SEARCH_DATA'] . "&searchmember=" . $m->MB_COUNTY . "\"" . $selected . ">" . $m->MB_COUNTY . " - " . html_entity_decode($m->MB_COUNTY) . "</option>";
                                }
                            }
                            ?>
                    </select>

                    <input type="hidden" name="SELECTED_MEMBER" value="<?php echo (isset($selected_member) ? $selected_member : "") ?>"/>
                </div>
            </div>



            <div class="form-group">
            <table class="table table-bordered table-striped table-hover">

            <thead>
            <tr>
                <th>
                   Name
                </th>
                <th>
                  Website
                </th>
                <th>
                   Phone
                </th>
                <th>
                    Address
                </th>
            </tr>
            </thead>


            <?php if($county != ""): ?> 
            <?php
                foreach($members as $m){
                    echo "<tr>";
                        echo "<td>";
                            echo "<span class=\"member_line\">" . $m->MB_COMPANY . "</span>";
                        echo "</td>";
                        echo "<td>";
                            echo "<a href=\"http://" . $m->MB_MOBILE . "\">" . $m->MB_MOBILE . "</a>";
                        echo "</td>";
                        echo "<td>";
                            echo "<span class=\"member_line\">" . $m->MB_PHONE . "</span>";
                        echo "</td>";
        //              echo "<td>";
        //                  echo "<a href=\"mailto:" . $m->MB_EMAIL . "\"><span style=\"color:#669999;\" class=\"member_line\">" . $m->MB_EMAIL . "</span></a>";
        //              echo "</td>";-->
                        echo "<td>";
                            echo "<span class=\"member_line\">" . $m->MB_ADDRESS1 . ", " . $m->MB_ADDRESS2 . ", " . $m->MB_TOWN . ", " . $m->MB_COUNTY . ", " . $m->MB_POSTCODE . "</span>";
                        echo "</td>";
                    echo "</tr>";
                }
                echo "</table>"; 
             ?>
             </table>

             <?php endif; ?>

             </div>
            </div>
            </form>  
        </section>
        <!-- end: Page section -->


        </div>

    </div>
</div>
<!-- end: Container -->



<?php
  include_once("includes/footer.php");
?>

1 个答案:

答案 0 :(得分:0)

您的PHP页面无法在没有页面刷新的情况下更改打包中的内容,或者使用javascript重写页面。

我看到你在下拉变化时使用了MM_jumpMenu()JS函数。此函数需要检索您选择的数据,然后重写表以包含新数据。如果您已经在JS代码中执行此操作,那么我们需要查看该代码以找出问题所在。

另一种方法是取消JS并允许表单将页面提交给自己。然后在页面顶部读取从表单传递的选定值,加载数据并相应地写入包。