dtf24224 2012-07-04 02:57
浏览 7
已采纳

从mysql_num_rows中选择查询

i want create multiple search where statement $where_search is a multiple condition from post form. but stil error when iam using this code ".where_search." in where condition with mysql_num_rows for paging

$tampil2 = mysql_query("SELECT * FROM bb where ".$where_search."  and kd_kelompok='2' and kd_komoditi='11' and nm_sebutan IS NOT NULL " );

this is the complete code.

$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);
  • 写回答

1条回答 默认 最新

  • douchaqi3369 2012-07-04 03:05
    关注

    Maybe your error is here:

    $where_search .= "AND tab1.kd_por = '$kd_por' ";
    

    Because you didn't declare the "tab1". Try change to this:

    $where_search .= "AND kd_por = '$kd_por' ";
    

    EDIT 1

    You didn't recovery the var $lakpus from $_POST befofe use it. Here is part of the code that you have to update.

    ...
    
    else
    {
    
        $lakpus = $_POST['lakpus'];
    
        if (empty($where_search))
        {
            $where_search .= "lakpus = '$lakpus' ";
        }
    
        ...
    

    EDIT 2

    As i said in the comments, try to call mysql_num_rows() after mysql_query(), like below.

    $qry = "SELECT * FROM bb where ".$where_search; 
    
    $res = mysql_query($qry); 
    
    $num = mysql_num_rows($res);
    
    $row = mysql_fetch_array($res); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计算二重积分∫∫e^(x+y)dxdy,其中0≤x≤1,0≤y≤1,试分别用复合辛普森公式(取n=4)以及高斯求积公式(取n=4)计算积分 给出matlab程序
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的