如何删除分页中的查询错误

时间:2014-02-20 13:24:59

标签: php pagination

我有一个函数,我从php页面调用但是当我调用函数时它会出错,这是我的代码:

function getbussinesspagination($profit_id,$start,$per_page)
{
    $select = "select a.title,a.credit,
                 (select name from main102.Location_4 where id=a.location_4) as cityName,
                 (select a.account_id from listing,article r 
                      where a.account_id=r.account_id 
                      group by a.account_id) as article,
                 (select a.account_id from listing,event e where a.account_id=e.account_id 
                      group by a.account_id) as event,
                 a.renewal_date, l.name 
               from listing a,
               listinglevel l LIMIT 
               where l.value=a.level and 
                 a.profit_instructor_id='".$profit_id."' 
                group by a.account_id '".$start."','".$per_page."'";
    $res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
    if ($res->num_rows > 0)
    {
        return $res;
    }
    else
    {
        return false;
    }
}

if($_POST['page'])
{
    $page = $_POST['page'];
    $cur_page = $page;
    $page -= 1;
    $per_page = 10;
    $start = $page * $per_page;
    include_once ("config.php"); 
    include_once ("function.php");
    $business = getbussinesspagination(0,$start,$per_page);
?>

当我执行页面时,它会给出错误

You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 
  'where l.value=a.level and a.profit_instructor_id='0' group by a.account_id '10',' 
  at line 221

1 个答案:

答案 0 :(得分:1)

LIMIT附近的sql语法有错误,请更正:

$select="select a.title,a.credit,
            (select name from main102.Location_4 where id=a.location_4) as cityName,
            (select a.account_id 
               from listing, article r 
               where a.account_id=r.account_id 
               group by a.account_id) as article,
            (select a.account_id from listing,event e 
              where a.account_id=e.account_id 
              group by a.account_id) as event,
         a.renewal_date, l.name 
         from listing a,listinglevel l  
         where l.value=a.level and a.profit_instructor_id='".$profit_id."' 
         group by a.account_id 
         LIMIT ".$start.", ".$per_page