将href链接到PHP搜索脚本的结果

时间:2016-11-01 03:14:12

标签: php html mysql codeigniter

我有一个像这样的简单搜索脚本,工作正常:

<html>
  <head>
    <title>any</title>  
    <link rel="stylesheet" type="text/css" href="style.css">
    <script>
      function check() {
        var searchtext = document.getElementById("txt").value;

        if(searchtext == '') {
          alert('Enter string to search');
        } else {
          document.myform.submit();
        }
      }

      function reset_table() {
        document.myform.submit();
      }
    </script>
  </head>
  <body>
    <?php
      error_reporting(0);
      require_once "config.php";

      $link = mysql_connect($hostname, $username, $password);
      $dbcon = mysql_select_db($dbname);

      echo "<div align='center' class='resp_code'>";
      echo "<h5><b>...</b></h5>";
      echo "<div align='center'>";
      echo "<form method='post' action='index.php' id='searchform' class='frms' name='myform'> 
              <input  type='text' id='txt' name='name' autocomplete='off'> 
              <input  type='submit' name='submit' value='Search' id='search' onclick='check();'>
              <input  type='submit' name='reset' value='Reset' id='reset' onclick='reset_table()'>
            </form> ";
      echo "</div>";
      echo "<div align='center'>";

      $search = $_POST["name"];

      if(isset($_POST['name'])) {   
        echo "<table class='table'>
                <tr>
                  <th>No.</th>
                  <th>Un.</th>
                  <th>img</th>
                </tr>";     

        $qry = mysql_query('SELECT * FROM rs_posts WHERE id like "%'.$search.'%"');
        $count = mysql_numrows($qry);

        if($count > 0) {
          if($qry) {    
            while($row = mysql_fetch_row($qry)) {      
              $num = $row['id'];
              $uniq = $row['unique_id'];
              $img = $row['featured_img']; 

              echo "<tr>
                      <td id='num'>$row[0]</td>
                      <td id='uniq'>$row[1]</td>
                      <td id='img'>$row[25]</td>
                    </tr>";
            }    
          } else {
            echo "No";
          }
        } else{
          $op = "No Results Found";
        }       
      }

      echo "</div>";
      echo "<div style='font-weight:bold;color:red;'>$op</div>";
      echo "</div>";
    ?>
  </body>
</html>

并有一个像这样的链接代码:

<a href="<?php echo site_url('property/'.$row->unique_id.'/'.rs_url_title($title));?>" target="_blank">link</a>

我需要一些像

这样的搜索结果
<td id='img'>$row[25]</td>

链接到那个。最简单的方法是什么?

如果接受提醒或点击“重置”按钮,它会显示我的数据库的所有内容,但是当我没有输入任何内容或点击“重置”按钮时,我需要隐藏它们。怎么能解决这个问题?

0 个答案:

没有答案