Jump to content

breaking results to pages


ryanmetzler3

Recommended Posts

I have this code that queries a DB and spits out results. But I have 147 results so far and counting. How can I change this code to echo maybe 20 a page? Also it displaying photos. So how can I make the results random? I don't want users to have to click through the first 3 pages of old results they have already seen if they revisit the site. 

<?php
		require 'connect2.php';
		$sql = mysql_query("SELECT imagelocation FROM store");
		
		while ($row = mysql_fetch_array($sql)) {
			$imgurl = $row['imagelocation'];
			echo "<img id='all' src=$imgurl>";
		}
		?>	

I have tried ORDER BY RANDOM() and LIMIT with the sql but it only got me so far. I can't figure out how to break it to multiple pages and the random function did not work with my code. Any guidance would be awesome!!

Link to comment
https://forums.phpfreaks.com/topic/281768-breaking-results-to-pages/
Share on other sites

Somethings you'll need to keep in mind...

 

    to randomize results while enforcing results requires you to store the 'randomizing' procedure (not truly random) from which you can offset or to at least store the previously presented results to exclude the next time around .

 

Generally speaking, pagination is not random.  If the filtering specifications or sort change, you can no longer guarantee what has or hasn't been displayed to the user.

 

We must select records using the same filter and sort procedures.

When the filter(s) and sort have been established, we can introduce a limit and offset to control portions.

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.