ryanmetzler3 Posted September 2, 2013 Share Posted September 2, 2013 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!! Quote Link to comment Share on other sites More sharing options...
PravinS Posted September 2, 2013 Share Posted September 2, 2013 search for "pagination code using php" on google, you will get the code Quote Link to comment Share on other sites More sharing options...
objnoob Posted September 2, 2013 Share Posted September 2, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.