dtrovwl75780 2011-10-09 10:30
浏览 33
已采纳

出乎意料 但我不明白为什么

Parse error: syntax error, unexpected ';' in /home/realcas/public_html/eshop/ecms/system/classes/database.php on line 29

This is the code on line 29

return empty($resultArray) ? "Error in Query " ? json_encode($resultArray);

this is the section of code that is the issue

public function select($table,$options,$where,$orderby)
{
    $options = empty($options) ? "*"   : $options;
    $where  =  empty($where)   ? "1=1" : $where;
    $orderby = empty($orderby) ? ""    : $orderby;

    $qry = "SELECT $options FROM $table WHERE $where $orderby ";
    $result = mysql_query($qry) or die(json_encode(array("error",mysql_error())));

    while(($resultArray[] = mysql_fetch_assoc($result)));
    return empty($resultArray) ? "Error in Query " ? json_encode($resultArray);

    return json_encode($resultArray);
}
  • 写回答

2条回答 默认 最新

  • dsmlf1207915 2011-10-09 10:31
    关注

    You want probably this one

    return empty($resultArray) ? "Error in Query " : json_encode($resultArray);
    

    because its

    ($condition) ? "condition is true" : "condition is false";
    

    I see you're using it already, so I assume it was just a typo

    Also remove this line

        return json_encode($resultArray);
    

    because it's unnecessary and never will happen. Additionally I'm not sure that your while loop is correct.

    Result

    public function select($table,$options,$where,$orderby)
    {
        $options = empty($options) ? "*"   : $options;
        $where  =  empty($where)   ? "1=1" : $where;
        $orderby = empty($orderby) ? ""    : $orderby;
    
        $qry = "SELECT $options FROM $table WHERE $where $orderby ";
        $result = mysql_query($qry) or die(json_encode(array("error",mysql_error())));
    
        while(($row = mysql_fetch_assoc($result))){ $resultArray[] = $row; }
        return count($resultArray) < 1 ? "Error in Query " : json_encode($resultArray);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM