I'm displaying the top 10 newest and the last 10 oldest topics after the 10 newest from database. I'm able to display what I need in the top 10 topics.My problem is that when I have 21 topics in database, the last 10 topics is displayed according to what I want,but when I have only 20 topics,the last topic in the newest will still be in the oldest.To make it more clear,here is a reference picture.
-This is what happen when I have 21 or more topics in database-
-This is what happen when I have 20 topics in database-
I don't want a topic to be repeated like what happen when I have 20 topics. Here is my code for fetching the last 10 topics from database:
// fetching last 10 topics from forum
function history() {
$sql = "SELECT * FROM (
SELECT f_id AS id, f_title AS name,f_dept AS dept,f_last_view AS last_view
FROM forum
ORDER BY last_view ASC
LIMIT 10 OFFSET 1
) AS `table` ORDER by last_view DESC ";
//-run the query against the mysql query function
$result=mysql_query($sql) or die(mysql_error());
$history = array();
//-create while loop and loop through result set
while (($row = mysql_fetch_assoc($result)) !== false){
$history[] = array(
'id' => $row['id'],
'name' => $row['name'],
'dept' => $row['dept'],
'last_view' => $row['last_view'],
);
}
return $history;
}
P.S. I know that mysql_* is deprecated but please bear with me. Thank you in advance