任何人都可以帮助我,我想建立一个搜索页面,将所有数据从value1输出到value2。我得到这个错误警告:mysql_num_rows()期望参数1是资源,
Search.php表格
<form action="Search.php" method="POST">
<input type="text" name="value1" placeholder="FROM TIME">
<input type="text" name="value2" placeholder="TO TIME">
<input type="submit" value=">>">
</form>
的search.php
<?php
mysql_connect("localhost","root","") or die("NO connection");
mysql_select_db("ci")or die("No DATABASE");
$value1 =$_POST['value1'];
$value2 =$_POST['value2'];
$output="";
if (isset($_POST ['value1'],$_POST['value2'])){
$result=mysql_query("SELECT * FROM slogs WHERE TIME BETWEEN
".$_POST['value2']." AND ".$_POST['value2']." ");
$count=mysql_num_rows($result);
if($count==0){
$output='You are not a student';
} else{
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$TIME.=$row['TIME']."</td>";
echo "<td>".$FN.=$row['FN']."</td>";
echo "<td>".$LN.=$row['LN']."</td>";
echo "<td>".$DT.=$row['DT']."</td>";
echo "</tr>";
}
}
}
?>
答案 0 :(得分:0)
您的搜索正在选择相同的两个值之间的数据。 试试这个:
<?php
mysql_connect("localhost","root","") or die("NO connection");
mysql_select_db("ci")or die("No DATABASE");
$value1 =$_POST['value1'];
$value2 =$_POST['value2'];
$output="";
if (isset($value1,$value2)){
$result=mysql_query("SELECT * FROM slogs WHERE TIME BETWEEN
". $value1 ." AND ". $value2 ." ");
$count=mysql_num_rows($result);
if($count==0){
$output='You are not a student';
} else{
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$TIME.=$row['TIME']."</td>";
echo "<td>".$FN.=$row['FN']."</td>";
echo "<td>".$LN.=$row['LN']."</td>";
echo "<td>".$DT.=$row['DT']."</td>";
echo "</tr>";
}
}
}
?>
答案 1 :(得分:0)
尝试在您查询的值周围添加单引号'
$result=mysql_query("SELECT * FROM slogs WHERE TIME BETWEEN '". $value1 ."' AND '". $value2 ."' ");