如何从搜索中获取信息以显示在表格中?

时间:2017-04-18 19:37:55

标签: php html mysql html-table

我在单独的页面上有一个搜索表单。我试图获取在该表单中搜索的信息显示在表中,同时还显示sql数据库中该搜索的其余数据。一点背景:这是一个图书馆使searxhing ob告更快。现在我已经摆脱了所有错误信息,并且显示了表格的标题和听众,但没有显示任何信息。完全披露:这不是所有原始代码,我在其他网站上找到的一些代码并修改它以适应我的需要。可以说,我可能错过了一些变化。

<?php
$servername = "localhost";
$username = "root";
$password = "*****";
$dbname = "hfa";

$link = mysqli_connect("localhost", "root", "*****", "hfa");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$_GET = array('first_name', 'last_name', 'age', 'year_of_birth', 
'year_of_death', 'date_of_death', 'month_of_death', 'funeral_home', 'city', 
'county'); 
    // gets value sent over search form

$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
$last_name = mysqli_real_escape_string($link, $_REQUEST['last_name']);
$age = mysqli_real_escape_string($link, $_REQUEST['age']);
$year_of_birth = mysqli_real_escape_string($link, 
$_REQUEST['year_of_birth']);
$year_of_death = mysqli_real_escape_string($link, 
$_REQUEST['year_of_death']);
$date_of_death = mysqli_real_escape_string($link, 
$_REQUEST['date_of_death']);
$month_of_death = mysqli_real_escape_string($link, 
$_REQUEST['month_of_death']);
$funeral_home = mysqli_real_escape_string($link, $_REQUEST['funeral_home']);
$city = mysqli_real_escape_string($link, $_REQUEST['city']);
$county = mysqli_real_escape_string($link, $_REQUEST['county']);

$sql = mysqli_query($link, "SELECT *
  FROM obituaries  
  WHERE FirstName AND LastName AND Age AND YearOfBirth AND YearOfDeath AND 
DateOfDeath AND MonthOfDeath AND FuneralHome AND City AND County
  LIKE ('$first_name' AND '$last_name' AND '$age' AND '$year_of_birth' AND 
'$year_of_death' AND '$date_of_death' AND '$month_of_death' AND 
'$funeral_home' AND '$city' AND '$county')");

  $q_res = mysqli_fetch_array($sql);

  $results = mysqli_fetch_row($sql);

 if(mysqli_query($link, "SELECT *
 FROM obituaries  
 WHERE FirstName AND LastName AND Age AND YearOfBirth AND YearOfDeath AND 
  DateOfDeath AND MonthOfDeath AND FuneralHome AND City AND County
LIKE ('$first_name' AND '$last_name' AND '$age' AND '$year_of_birth' AND 
  '$year_of_death' AND '$date_of_death' AND '$month_of_death' AND 
  '$funeral_home' AND '$city' AND '$county')")){
    echo "Success ";
 } else{
    echo "ERROR: Not able to execute $sql. " . mysqli_error($link);
 }
?>
<html>
  <head>
    <h1>Results</h1>
  </head>
  <body>
    <table style="width:100%">
     <thead>
      <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Age</th>
        <th>Year Of Birth</th>
        <th>Year Of Death</th>
        <th>Date Of Death</th>
        <th>Month Of Death</th>
        <th>City</th>
        <th>County</th>
        <th>Funeral Home</th>
      </tr>
     </thead>
     <tbody>
      <tr style="width:100%">
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

           while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['FirstName']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['LastName']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['Age']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['YearOfBirth']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['YearOfDeath']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['DateOfDeath']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['MonthOfDeath']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['City']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['County']."</h3></p>";
        } 
  } ?> </th>
        <th> <?php   if(mysqli_num_rows($sql) > 0){ 

          while($results = mysqli_fetch_array($sql)){

             echo "<p><h3>".$results['FuneralHome']."</h3></p>";
        } 
  } ?> </th>
      </tr>
     </tbody> 
    </table>
 </html>
<?php
$link->close();
?>

我不知道为什么不打印数据,有人可以帮忙吗?

0 个答案:

没有答案