我想创建多个搜索where语句$where_search是post表单中的多个条件。但是当我使用这个代码“.where_search”时,仍然是错误的。在where条件下使用mysql_num_rows进行分页
$tampil2 = mysql_query("SELECT * FROM bb where ".$where_search." and kd_kelompok='2' and kd_komoditi='11' and nm_sebutan IS NOT NULL " );这是完整的代码。
$where_search = "kd_pok='2' and kd_komoditi='11' ";
if (isset($_POST['lakpus']))
{
if (empty($_POST['lakpus']))
{
}
else
{
if (empty($where_search))
{
$where_search .= "lakpus = '$lakpus' ";
}
else
{
$where_search .= "AND lakpus = '$lakpus' ";
}
}
}
if (isset($_POST['kd_por']))
{
$kd_por = $_POST['kd_por'] ;
if (empty($_POST['kd_por']))
{
}
else
{
if (empty($where_search))
{
$where_search .= "kd_por = '$kd_por' ";
}
else
{
$where_search .= "AND tab1.kd_por = '$kd_por' ";
}
}
}
$max=15;
$tampil2 = mysql_query("SELECT * FROM bb where ".$where_search." and kd_kelompok='2' and kd_komoditi='11' and nm_sebutan IS NOT NULL " );
$jml = mysql_num_rows($tampil2);
$jmlhal = ceil($jml/$max);发布于 2012-07-04 11:05:46
也许你的错误在这里:
$where_search .= "AND tab1.kd_por = '$kd_por' ";因为你没有声明"tab1“。尝试将其更改为:
$where_search .= "AND kd_por = '$kd_por' ";编辑1个
在使用之前,您没有从$_POST中恢复var $lakpus。以下是您必须更新的代码的一部分。
...
else
{
$lakpus = $_POST['lakpus'];
if (empty($where_search))
{
$where_search .= "lakpus = '$lakpus' ";
}
...编辑2个
正如我在评论中所说的,尝试在mysql_query()之后调用mysql_num_rows(),如下所示。
$qry = "SELECT * FROM bb where ".$where_search;
$res = mysql_query($qry);
$num = mysql_num_rows($res);
$row = mysql_fetch_array($res); https://stackoverflow.com/questions/11321864
复制相似问题