私のPHPスクリプトでページネーションエラーが発生しました。 mysql workbenchの中で直接実行され、適切な結果が返ってくると、クエリは正常に動作します。PHPページ区切りクエリが失敗しました
エラーが返されました:SQL構文にエラーがあります。私は、テーブルにそれらの結果を表示しています2
$getpositive = "select case_number, c.name as subject, a.name, u.first_name, u.last_name from cases as c join cases_cstm as cc on c.id = cc.id_c
left join accounts as a on a.id = c.account_id left join users as u on u.id = c.assigned_user_id where rating_c ='1';";
$db -> PS_Pagination($getpositive, 20, 5, "");
$db -> setDebug(true);
$rs = $db->paginate();
$positive_rating_rows = mysql_num_rows($rs);
ラインに近い使用する権利構文についてはMySQLサーバのバージョンに対応するマニュアルを確認し「LIMIT 0、20」:
while($val = mysql_fetch_assoc($rs))
{
?>
</tr>
<tr>
<td width="7%"><?=$val['case_number']?></td>
<td width="40%"><?=$val['subject']?></td>
<td width="40%"><?=$val['name']?></td>
</tr>
ここに私のページネーション機能は次のとおりです。
public function PS_Pagination($sql, $rows_per_page = 10, $links_per_page = 5, $append = "") {
//$this->conn = $connection;
$this->sql = $sql;
$this->rows_per_page = (int)$rows_per_page;
if (intval($links_per_page) > 0) {
$this->links_per_page = (int)$links_per_page;
} else {
$this->links_per_page = 5;
}
$this->append = $append;
$this->php_self = htmlspecialchars($_SERVER['PHP_SELF']);
if (isset($_GET['page'])) {
$this->page = intval($_GET['page']);
}
}
public function paginate() {
//Check for valid mysql connection
if (! $this->IsConnected()) {
$this->SetError("No connection");
return false;
}
//Find total number of rows
$all_rs = @mysql_query($this->sql);
if (! $all_rs) {
if ($this->debug)
echo "SQL query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
return false;
}
$this->total_rows = mysql_num_rows($all_rs);
@mysql_close($all_rs);
//Return FALSE if no rows found
if ($this->total_rows == 0) {
if ($this->debug)
//echo "Query returned zero rows.";
return FALSE;
}
//Max number of pages
$this->max_pages = ceil($this->total_rows/$this->rows_per_page);
if ($this->links_per_page > $this->max_pages) {
$this->links_per_page = $this->max_pages;
}
//Check the page value just in case someone is trying to input an aribitrary value
if ($this->page > $this->max_pages || $this->page <= 0) {
$this->page = 1;
}
//Calculate Offset
$this->offset = $this->rows_per_page * ($this->page - 1);
//Fetch the required result set
//echo $this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}";
$rs = @mysql_query($this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}");
if (! $rs) {
if ($this->debug)
echo "Pagination query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
return false;
}
return $rs;
}
実際のエラーメッセージを投稿すると、$ dbクラス(特にPS_Paginationとpaginate関数)の抜粋も役立ちます。 – Oldskool
エラーを追加しました。私はページ設定関数がどこにあるのかわかりません。 – ipengineer
明らかに、関数の1つが(少なくとも 'LIMIT 0、20'ビットを追加するだけで)クエリを変更しているので、これを担当する関数を見ることが重要です。さもなければ私達は解決策を考え出すことができません。 – Oldskool