請幫助我。我遇到了一個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"));