Jump to content

Is this correct?


dc_jt

Recommended Posts

Hi

 

Ive got a table which contain many advice articles. Each article has got a category. The table is as follows:

 

advice_id | category_id | title | content | position

 

I want to make page numbering so that when you are in advice_id 10 which is position 0, you can click next and this will go to advice_id 9, position 1 then next again takes you to advice_id 8, position 2. Then if you click previous you will go from position 2 to position 1 etc.

 

Here is what I have done:

 

public function GetNextPage($iPosition)
{
	$db = new RCDB;

	$query = "SELECT *
	FROM advice 
	WHERE category = 'Choosing'
	&& position > '$iPosition'";

	$query .= " ORDER BY position ASC LIMIT 0,1";

	return $db->query($query);
}

public function GetPreviousPage($iPosition)
{
	$db = new RCDB;

	$query = "SELECT *
	FROM advice 
	WHERE category = 'Choosing'
	&& position < '$iPosition'";

	$query .= " ORDER BY position DESC LIMIT 0,1";

	return $db->query($query);
}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/55277-is-this-correct/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.