Jump to content

adding pagination to a random display of data


barrowvian

Recommended Posts

Currently I have this;

					<?php 
					// orders and displays the results randomly in rows of 16.
					$_num = 0;
					$result = mysql_query("SELECT image_link FROM adverts ORDER BY RAND()",$connection);

					while($row = mysql_fetch_array($result)){
						echo $row['image_link'] . " ";
						$_num++;

						if ($_num == 16){
								echo "<br />";
  								$_num = 0;
							}
					}			
				?>

 

It simply queries my database at returns the results in a random order.

 

Now what I am wanting to do is add pagination but still keep the display random. How would I go about doing this? I have been looking through the pagination tutorial here on php freaks and have the pagination working on its own, but now I am wanting to combine the two but have no idea what to do :)

 

Link to comment
Share on other sites

Here's a fairly simple pagination class file that I use all the time. It's simple, but it still gives you a page list, next page, previous page, etc., all from just an array, per page number, and current page number.

 

[attachment deleted by admin]

Link to comment
Share on other sites

	<?php 
$allRows = array();
$result = mysql_query("SELECT image_link FROM adverts ORDER BY RAND()",$connection);
while($row = mysql_fetch_array($result)){
$allRows[] = $row;
}

// Now you can use $allRows with the pagination class

?>

Link to comment
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.