显示db中包含空表单字段的所有记录

时间:2011-03-27 14:36:43

标签: php mysql forms

当您未在表单

中输入任何字段时,是否可以从数据库中获取所有记录 像这样的东西,某种条件查询 我有一个查询$查询,在填写表单后获取一些数据,但是当字段country和work为空时,我需要一个evet来显示数据库中的所有数据 还有两个其他日期字段用于在某个时间间隔内过滤结果 代码是: ...

$country = $_GET['country'];
$work = $_GET['work'];

if ($country == 0 and $work == 0)
echo $query1;
else $query;

$query1 = "SELECT ...."
$query = "SELECT...."

.....

感谢

编辑> 嗨,我试过了,它返回所有数据,这是可以的。 _但现在我有错误:填写表单字段时查询为空。代码就像这样:

if (empty($country) and empty($work))
{
$query1 = "SELECT row_number, country, project_type, code, start_date, end_date, work, name
FROM eng WHERE 
start_date
BETWEEN \"$start_date\" and \"$end_date\"
ORDER BY country ASC";
};
$query = "
SELECT row_number, country, project_type, code, start_date, end_date, work, name
FROM eng WHERE 
country = \"$country\" AND work LIKE '%$work%' AND start_date
BETWEEN \"$start_date\" and \"$end_date\"
ORDER BY start_date ASC";
$qry_result = mysql_query($query) or die(mysql_error());
$qry_result1 = mysql_query($query1) or die(mysql_error());

1 个答案:

答案 0 :(得分:0)

if (empty($country) and empty($work)){
$query = "SELECT * from table....";
};

这应该可以正常工作。

此外,您应该使用POST方法与表单,而不是GET