【问题标题】:How to Get the table name in database with select box?如何使用选择框获取数据库中的表名?
【发布时间】:2014-05-03 07:50:46
【问题描述】:

最近,我正在创建一个学校图书馆 Ser,在数据库(Newlibrary)中有三个表。 三表是 - 经济书籍,地理书籍,化学书籍 在每个表中,它都有(学生姓名)和(电话号码)。 我想创建一个糟糕的搜索引擎(下拉列表 - 使用选择表)并输入(电话 选择了哪个表) 这是代码,如何使用下拉列表选择表格(经济书籍或地理书籍或化学书籍)并输入电话以在同时选择的表格中搜索?

((index.html))

    <form method="GET" action="searchtitle">
          <select name="booktype" value="<?=$['booktype']?>">
  <option value="" selected="selected"></option>
  <option value="a">Econbooks</option>
  <option value="b">Geobooks</option>
  <option value="c">Chembooks</option>
            </select>

    <input id="inputkeyword" type="text" name="keyword" placeholder="Please enter a keyword...."/>
    <input type="submit" class="keyword" value="search" />  
</form>

((searchtitle.php))

    <?php

      $keyword = $_GET['keyword'];
      $con = mysql_connect("localhost","root","password");
      mysql_select_db("newlibrary");

      $sql = "Select * from borrower
      where  Telp='$keyword' ";

      $results = mysql_query($sql,$con);


      if(mysql_num_rows($results) == 0)  {echo "<h1>No Record Has Been Found!!</h1> ";} else { 

  echo "<table id='borrowertable'  >
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Tel</th>
    </tr>" ;
   while($row = mysql_fetch_array($results)) { 

    $bid = $row[0];
       $Names = $row[1];
   $Tel = $row[2];


    echo "  <tr>
            <td>$bid</td>
            <td>$Names</td>
            <td>$Tel</td>
        </tr>";

        } 

 }

    mysql_close($con);
   echo "<p> <a href='index'>Back Home</a> ";
  ?>

怎么改?

【问题讨论】:

    标签: php html mysql sql-server


    【解决方案1】:

    如果我没听错,您需要能够根据用户的选择使用电话号码搜索三个表之一。我不确定你是否想使用 Javascript,希望这会有所帮助

    首先您需要将 Select 和文本框的值都传递给 searchtitle.php

    function get_User() {
    
    var user_data = {};
    user_data['Book'] = document.getElementById("DropDownID").value; // get dropdown selected value
    user_data['phone'] = document.getElementById("inputkeywor").value; // get dropdown selected value
    
    
    $.ajax({
    
        type: "POST",
    
        url: "searchtitle.php",
    
        beforeSend: function () {
    
        $( "#LoadingDiv" ).html("Searching User...");
    
        },
    
        data: user_data,
    
        success: function (data) {
    
        Here Data is the result of searchTtitle.php.....
    
    
        }}}); 
    

    然后在searchtitle.php 上,您可以从

      $keyword = $_POST['phone'];
      $TableToQuery = $_POST['Book'];
    

    在提交时调用 get_User

     <input type="button" class="keyword" value="search" onclick="get_User()" /> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-01
      • 1970-01-01
      • 2018-10-12
      • 2019-10-06
      • 2019-03-23
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      相关资源
      最近更新 更多