请帮助我。我遇到了一个DataTable警告,如“DataTables警告:服务器的JSON数据无法解析,这是由JSON格式错误导致的。”在使用PHP的Zend框架中,使用JSON编码。无法解析来自服务器的JSON数据。这是由Zend框架中的JSON格式错误引起的,同时使用
这个警告只发生在表为空时,但是这个问题只是在sql查询中使用group关键字时才会出现,如果我不使用group关键字,那么它只给出表中的一条记录,但表中有更多记录也。当我使用以下查询时,输出变为显示所有记录,只有表中有数据,如果不显示数据表示警告。 // sql查询(型号/表/ product.php)
public function fetchAllProductItems() {
$oSelect = $this->select()
->setIntegrityCheck(false)
->from(array("p" => "products","b" => "bid"), ('*'))
->joinLeft(array("b" => "bid"), "b.product_id=p.product_id", array('bid_id','bid_amount'))
->joinInner(array("e" => "employees"), "e.employee_id=p.employee_id",array('ename'))
->where("p.verified = ?", "Yes")
->where("p.sold_out = ?", "No")
->group('p.product_id')
->having("p.sale_end_date >= ?", date("Y-m-d"));
return $oSelect;
}
// JSON编码(模块/销售/控制器/ apicontroller)
public function getProductsAction()
{
$oProductModel = new Application_Model_Db_Table_Products();
$oSelect = $oProductModel->fetchAllProductItems();
echo Zend_Json::encode($this->_helper->DataTables($oSelect, array('product_id','e.ename as employee_name','name', 'brand', 'conditions', 'about','image_path', 'reserved_price', 'Max(b.bid_amount) as amount')));
}
下面的查询将只显示一个记录,如果表中有多个记录。如果表格是空的,那么我会来“表格消息中没有数据可用”。
// sql查询(型号/表/ product.php)
$oSelect = $this->select()
->setIntegrityCheck(false)
->from(array("p" => "products","b" => "bid"), ('*'))
->joinLeft(array("b" => "bid"), "b.product_id=p.product_id", array('bid_id','bid_amount'))
->joinInner(array("e" => "employees"), "e.employee_id=p.employee_id",array('ename'))
->where("p.verified = ?", "Yes")
->where("p.sold_out = ?", "No")
->where("p.sale_end_date >= ?", date("Y-m-d"));