To pytanie jest stare, ale chcę tylko dodać kod, który nie jest na sztywno, a podany chaos odpowiedzi oznacza, że będziesz musiał skasować swoje skrypty (Instrukcja Select). możesz osiągnąć te same wyniki, pobierając nazwę pliku, a następnie wybierając dane z bazy danych na podstawie bieżącej strony, bez zakodowania instrukcji wyboru. najpierw uzyskać bieżącej strony
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page_counter = rtrim($page, ".php");
//setting your limit
$start = 0;
$limit = 10;
//if current page is not index.php then $start = ($limit * page_counter);
// e.g if current page is 1.php then $start = ($limit * 1) = 10
//if current page is 2.php then $start = ($limit * 2) = 20
if ($page !== 'index.php') {
$start = ($limit * $page_counter);
}
//getting row count
$ROW_COUNT = $db->query('SELECT * from tableName')->rowCount();
//getting number of rows left in the table
$rows_left = ("SELECT * FROM tableName limit ?,?");
$rows_left = $db->prepare($rows_left);
$rows_left->execute(array($start,$ROW_COUNT));
$rows = $rows_left->fetchAll(PDO::FETCH_ASSOC);
$number_rows = 0;
foreach ($rows as $r) {
$number_rows = $number_rows + 1;
}
//if number of rows left in the table is less than 10 then $limit = the number of rows left
if ($number_rows < 10) {
$limit = $number_rows;
}
//getting all rows
$getRows = "SELECT * FROM tableName limit ?,?";
$getRows = $db->prepare($getRows);
$getRows->execute(array($start , $limit));
$getRows = $getRows->fetchAll(PDO::FETCH_ASSOC);
Spróbuj mysql_query ("SELECT * FROM' picdb' WHERE 'username' = '$ username' ORDER BY' picid' DESC LIMIT $ start, $ count") – Rufinus
Re edycji, należy uzyskać swoją opinię błąd ustanowionego do tego stopnia, że powie ci, co jest nie tak z twoim SQL. Przekonasz się, że masz błąd składni, ponieważ twoja klauzula "LIMIT" jest przed twoją klauzulą "ORDER BY". – chaos
dzięki chłopaki, działa dobrze teraz. – mrpatg