Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.