Jump to content

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.

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.