• <tfoot id='ZoCNv'></tfoot>
    <legend id='ZoCNv'><style id='ZoCNv'><dir id='ZoCNv'><q id='ZoCNv'></q></dir></style></legend>

    1. <i id='ZoCNv'><tr id='ZoCNv'><dt id='ZoCNv'><q id='ZoCNv'><span id='ZoCNv'><b id='ZoCNv'><form id='ZoCNv'><ins id='ZoCNv'></ins><ul id='ZoCNv'></ul><sub id='ZoCNv'></sub></form><legend id='ZoCNv'></legend><bdo id='ZoCNv'><pre id='ZoCNv'><center id='ZoCNv'></center></pre></bdo></b><th id='ZoCNv'></th></span></q></dt></tr></i><div id='ZoCNv'><tfoot id='ZoCNv'></tfoot><dl id='ZoCNv'><fieldset id='ZoCNv'></fieldset></dl></div>
        • <bdo id='ZoCNv'></bdo><ul id='ZoCNv'></ul>
      1. <small id='ZoCNv'></small><noframes id='ZoCNv'>

      2. 如何从数据库中的mysqli输入中搜索值

        时间:2023-09-24
          <tbody id='NJnCW'></tbody>

      3. <tfoot id='NJnCW'></tfoot>

      4. <legend id='NJnCW'><style id='NJnCW'><dir id='NJnCW'><q id='NJnCW'></q></dir></style></legend>
            <bdo id='NJnCW'></bdo><ul id='NJnCW'></ul>

              <small id='NJnCW'></small><noframes id='NJnCW'>

              <i id='NJnCW'><tr id='NJnCW'><dt id='NJnCW'><q id='NJnCW'><span id='NJnCW'><b id='NJnCW'><form id='NJnCW'><ins id='NJnCW'></ins><ul id='NJnCW'></ul><sub id='NJnCW'></sub></form><legend id='NJnCW'></legend><bdo id='NJnCW'><pre id='NJnCW'><center id='NJnCW'></center></pre></bdo></b><th id='NJnCW'></th></span></q></dt></tr></i><div id='NJnCW'><tfoot id='NJnCW'></tfoot><dl id='NJnCW'><fieldset id='NJnCW'></fieldset></dl></div>

                  本文介绍了如何从数据库中的mysqli输入中搜索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在使用值的第一个字符时显示我的数据库值.让我用我的网站来描述它我有一个带有主页输入的网站,其中用户键入输入作为火车号.我需要那个用户类型的火车号.他从我存储的数据库中获得了火车名称.

                  解决方案

                  检查此代码.我认为它会对您有所帮助

                  <头><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>PHP、jQuery搜索演示</title><link rel="stylesheet" type="text/css" href="my.css"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript">$(document).ready(function () {$("输入").keyup(function () {$('#results').html('');var searchString = $("#search_box").val();var data = 'search_text=' + searchString;如果(搜索字符串){$.ajax({类型:POST",网址:'search.php',数据:数据,数据类型:'文本',异步:假,缓存:假,成功:功能(结果){$('#results').html(result);//window.location.reload();}});}});});<身体><div id="容器"><div style="margin:20px auto; text-align: center;"><form method="post" action="do_search.php"><input type="text" name="search" id="search_box" class='search_box'/><input type="submit" value="Search" class="search_button"/><br/></表单>

                  <div><div id="searchresults">搜索结果:</div><ul id="results" class="update">

                  首先为您输入的输入字段创建 html 和 jquery 代码然后调用使用ajax方法命中数据库的jquery函数keyup然后创建一个 php 文件来管理您的搜索 我创建了一个 search.php 文件

                  connect_error){die("连接失败:" . $conn->connect_error);}$sql = "从 yourtable_name WHERE match_text LIKE '%$searchquery%' 中选择字段 1,字段 2";$result = $conn->query($sql);如果($result->num_rows>0){//输出每一行的数据while($row = $result->fetch_assoc()) {回声-名称:".$row["filed1"]."".$row["field2"]."<br>";}} 别的 {echo "0 结果";}$conn->close();?>

                  从此页面您将获得搜索结果,您可以根据需要进行更改.为了您的检查,您还可以添加搜索文本长度,如果您不搜索,如果搜索文本长度 > 2 或 etc

                  I want to show my database value when use type first character of the value. Let me describe it with my site I have a website with homepage input where user type input as train no. I need that user type train no. he got train name from my database where i store.

                  解决方案

                  check this code .i think it will help you

                  <html>
                   <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                  <title>PHP, jQuery search demo</title>
                  <link rel="stylesheet" type="text/css" href="my.css">
                  
                  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
                  <script type="text/javascript">
                      $(document).ready(function () {
                          $("input").keyup(function () {
                              $('#results').html('');
                              var searchString = $("#search_box").val();
                              var data = 'search_text=' + searchString;
                              if (searchString) {
                                  $.ajax({
                                      type: "POST",
                                      url: 'search.php',
                                      data: data,
                                      dataType: 'text',
                                      async: false,
                                      cache: false,
                                      success: function (result) {
                                          $('#results').html(result);
                                          //window.location.reload();
                  
                                      }
                                  });
                              }
                          });
                      });
                    </script>
                  
                   </head>
                    <body>
                   <div id="container">
                   <div style="margin:20px auto; text-align: center;">
                      <form method="post" action="do_search.php">
                          <input type="text" name="search" id="search_box" class='search_box'/>
                          <input type="submit" value="Search" class="search_button"/><br/>
                      </form>
                  </div>
                  <div>
                  
                      <div id="searchresults">Search results :</div>
                      <ul id="results" class="update">
                      </ul>
                  
                  </div>
                  </div>
                  
                  </body>
                  </html>
                  

                  first create html and jquery code for input field which you type then call jquery function keyup which hit database using ajax method then create a php file which manage your search i create a search.php file

                  <?php
                    $servername = "localhost";
                    $username = "db_username";
                    $password = "db_password";
                    $dbname = "your_db_name";
                    $searchquery = trim($_POST['search_text']); //input for search
                    // Create connection
                    $conn = new mysqli($servername, $username, $password, $dbname);
                    // Check connection
                    if ($conn->connect_error) {
                    die("Connection failed: " . $conn->connect_error);
                    }
                  
                   $sql = "SELECT  filed1, field2 FROM yourtable_name WHERE match_text LIKE '%$searchquery%'";
                  $result = $conn->query($sql);
                  
                  if ($result->num_rows > 0) {
                  // output data of each row
                  while($row = $result->fetch_assoc()) {
                      echo " - Name: " . $row["filed1"]. " " . $row["field2"]. "<br>";
                  }
                  } else {
                  echo "0 results";
                  }
                  $conn->close();
                  ?>
                  

                  from this page you will get your search result and you can change it as your demand . for your check you can also add search text length if you do not search if search text length > 2 or etc

                  这篇关于如何从数据库中的mysqli输入中搜索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP:为什么我不能在 mysqli_fetch_array() 结果上循环两 下一篇:通过php将html表单数据发送到sql数据库(使用mysql

                  相关文章

                  最新文章

                  <small id='3BjMl'></small><noframes id='3BjMl'>

                  <tfoot id='3BjMl'></tfoot>
                1. <i id='3BjMl'><tr id='3BjMl'><dt id='3BjMl'><q id='3BjMl'><span id='3BjMl'><b id='3BjMl'><form id='3BjMl'><ins id='3BjMl'></ins><ul id='3BjMl'></ul><sub id='3BjMl'></sub></form><legend id='3BjMl'></legend><bdo id='3BjMl'><pre id='3BjMl'><center id='3BjMl'></center></pre></bdo></b><th id='3BjMl'></th></span></q></dt></tr></i><div id='3BjMl'><tfoot id='3BjMl'></tfoot><dl id='3BjMl'><fieldset id='3BjMl'></fieldset></dl></div>

                        <bdo id='3BjMl'></bdo><ul id='3BjMl'></ul>
                      <legend id='3BjMl'><style id='3BjMl'><dir id='3BjMl'><q id='3BjMl'></q></dir></style></legend>