查看表中mysql数据库的查询数据

时间:2015-08-27 17:30:41

标签: php mysql

我正在尝试更新网页搜索功能的代码,现在它没有返回任何内容。我已经使用了一段时间而没有从中得到任何东西。

这是HTML搜索代码:

float

PHP

<form method="post" action="words_results1.php">
<table align="center">
  <tr>
<td>Keyword</td>
<td><input type="text" name="Keyword" /></td>
</tr>
  <tr>
    <td>Author</td>
    <td><input type="text" name="Author" /></td>
  </tr>
  <tr>
    <td valign=bottom>Words Posted<BR />on or before</td>
    <td valign=top>
      <table>
        <tr>
          <td width="33%">Day</td>
          <td width="33%">Month</td>
          <td width="34%">Year</td>
        </tr>
        <tr>
      <td>
            <select name=Day>
            <?php
              echo '<option></option>';
              for($count = 1; $count <= 31; ++$count)
              {
                echo "<option>$count</option>";
              }
            ?>
            </select>
          </td>
          <td>
            <select name=Month>
            <?php
              echo '<option></option>';
              for($count = 1; $count <= 12; $count++)
              {
                 echo "<option value=$count>".date("M", mktime(0,0,0,$count,1, 2000))."</option>";
              }
            ?>
            </select>
          </td>
          <td>
            <select name=Year>
             <?php
              echo '<option></option>';
              for($count = date("Y"); $count >= 1997; $count--)
              {
                echo "<option>$count</option>";
              }
            ?>
            </select>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan=2 align=center>
      &nbsp;<BR />
      <input type="submit" value="Search" />
      &nbsp;&nbsp;&nbsp;
      <input type="submit" name="cancel" value="Cancel" />
    </td>
  </tr>
</table>    
</form>

最后一位是构成表格的代码,我假设问题出在这里,但老实说我现在还不确定

<?php 

if(isset($_POST['cancel']))
  {
    echo("index.html");
    exit;
  }

  $qry_string = "SELECT * FROM Words";
  $search = "";

  if(!empty($Keyword))
  {
    $End_String = "(Word LIKE '%$Keyword%' OR Title LIKE '%$Keyword%')";
    $search .="&Keyword=$Keyword";
  }

  if(!empty($Author))
  {
    if(isset($End_String))
    {
      $End_String .= " AND (Author LIKE '%$Author%')";
    }
    else
    {
      $End_String = "(Author LIKE '%$Author%')";
    }
    $search .="&Author=$Author";
  }

  if(!empty($Day))
  {
    if(isset($End_String))
    {
      $End_String .= " AND (DAYOFMONTH(Date_Created) = '$Day')";
    }
    else
    {
      $End_String = "(DAYOFMONTH(Date_Created) = '$Day')";
    }
    $search .="&Day=$Day";
   }

  if(!empty($Month))
  {
    if(isset($End_String))
    {
      $End_String .= "AND (MONTH(Date_Created) = '$Month')";
    }
    else
    {
      $End_String = "(MONTH(Date_Created) = '$Month')";
    }
    $search .="&Month=$Month";
  }

  if(!empty($Year))
  {
    if(isset($End_String))
    {
      $End_String .= " AND (YEAR(Date_Created) = '$Year')";
    }
    else
    {
      $End_String = "(YEAR(Date_Created) = '$Year')";
    }
    $search .="&Year=$Year";
  }

  if (!isset($offset)) $offset=0;

  if(isset($End_String))
  {
    $qry_string = $qry_string." WHERE ".$End_String . " ORDER BY Date_Created DESC LIMIT $offset,101";
  }
  else
  {
    $qry_string = $qry_string." ORDER BY Date_Created DESC LIMIT $offset,101";
  }

//  echo $qry_string . "<P><HR><P>";
  $result = mysql_query($qry_string);
echo mysql_error();
?>

1 个答案:

答案 0 :(得分:0)

看来,你没有收集

的价值
$Keyword=$_POST['Keyword'];

并添加,关闭表格标签以正确显示表格格式的结果。