473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Random Order Help Request - prevent previously displayed objects

I have a query that is showing new items in a store based upon their
inventory date. The problem with my Random order sort is that when the
"next" link is pressed, the random function is called again and I may see
the image previously displayed rather than go through the entire new
inventory.

Any suggestions on how to prevent that occurrence?

SELECT *
FROM `Catalog`
WHERE (`Catalog`.thumbnail LIKE '%-04.%' or `Catalog`.thumbnail LIKE
'%-05.%' or`Catalog`.thumbnail LIKE '%-03.%' ) and `Catalog`.img_status =
'1' and `Catalog`.views != '0' ORDER BY RAND()
Thanks
Jeff
~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.com

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #1
4 1705

"Jefferis NoSpamme" <je********@hotmail.com> wrote
I have a query that is showing new items in a store based upon their
inventory date. The problem with my Random order sort is that when the
"next" link is pressed, the random function is called again and I may see
the image previously displayed rather than go through the entire new
inventory.


Couple of ideas:

1. Make up a pseudo-random sort order, say, by combining several fields
together, and save the last key fields displayed in a session variable.

When they hit next, use the session key variable to bound your search.

2. Alternatively, if not a high volume site, put the entire result set of
your rand() ordered query (all rows) in a session variable, and store the
highest row displayed in a session variable for use by the "next" logic.

3. Add a random column (randcol) to your table, and refresh it every x
hours or days to reshuffle the deck, so to speak. Sort the query by randcol,
unique_Id (possible for two rows to have the same random number). Save the
last displayed key in-session and bound your "next" search by that saved
key.

-- Dan
Jul 17 '05 #2
Thanks Dan. I'll think on these options.

Jeff
On 3/8/05 2:35 PM, in article
38**************@newsread1.news.pas.earthlink.net, "Dan Stumpus"
<ds***********@mindspring.com> wrote:
together, and save the last key fields displayed in a session variable.

When they hit next, use the session key variable to bound your search.

2. Alternatively, if not a high volume site, put the entire result set of
your rand() ordered query (all rows) in a session variable, and store the
highest row displayed in a session variable for use by the "next" logic.

3. Add a random column (randcol) to your table, and refresh it every x
hours or days to reshuffle the deck, so to speak. Sort the query by randcol,
unique_Id (possible for two rows to have the same random number). Save the
last displayed key in-session and bound your "next" search by that saved
key.


~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.com

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #3
On Tue, 8 Mar 2005, Jefferis NoSpamme wrote:
I have a query that is showing new items in a store based upon their
inventory date. The problem with my Random order sort is that when the
"next" link is pressed, the random function is called again and I may
see the image previously displayed rather than go through the entire new
inventory.

Any suggestions on how to prevent that occurrence?


Assuming you are using sessions, you could seed the database's RAND()
function with a value which you create for each new visit and save in the
PHP session.

That way each visit would get a (different) randomized list but the order
would stay constant throughout the course of the visit.

Something like:

<?

if (!array_key_exists("randomseed", $_SESSION)) {
$_SESSION["randomseed"] = time();
}

mysql_query("SELECT ... ORDER BY RAND($_SESSION[randomseed])");

?>

--
Matt

Jul 17 '05 #4
Thanks Matt.

The client decided just to limit the page to this year's items which was an
easy fix. It isn't random, but the limited number of items make it less
important.
On 3/9/05 12:03 PM, in article
Pi*******************************@hermes.athens, "Matt Raines"
<matt@rai#remove#nes.me.uk> wrote:
On Tue, 8 Mar 2005, Jefferis NoSpamme wrote:
I have a query that is showing new items in a store based upon their
inventory date. The problem with my Random order sort is that when the
"next" link is pressed, the random function is called again and I may
see the image previously displayed rather than go through the entire new
inventory.

Any suggestions on how to prevent that occurrence?


Assuming you are using sessions, you could seed the database's RAND()
function with a value which you create for each new visit and save in the
PHP session.

That way each visit would get a (different) randomized list but the order
would stay constant throughout the course of the visit.

Something like:

<?

if (!array_key_exists("randomseed", $_SESSION)) {
$_SESSION["randomseed"] = time();
}

mysql_query("SELECT ... ORDER BY RAND($_SESSION[randomseed])");

?>

--
Matt


~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.com

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bart Nessux | last post by:
New to Python... trying to figure out how to count the objects in a list and then map the count to the objects or convert the list to a dict... I think the latter would be better as I need a number...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
1
by: Patrick | last post by:
Hi, This post is the 'sequel' ;) of the "Data Oriented vs Object Oriented Design" post, but it can be read and treated apart from that one. I will just quote the beginning of my previous message...
15
by: felixnielsen | last post by:
This is something i have done before and i know its pretty simple, however i cant remember how it works exactly, and i need it i kinda hurry, so if someone would be so nice to drop a random number...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
19
by: Boris Borcic | last post by:
does x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) pick a random shuffle of x with uniform distribution ? Intuitively, assuming list.sort() does a minimal number of comparisons to ...
3
by: Cindy | last post by:
I'm trying to use the NEWID function in dynamic SQL and get an error message Incorrect syntax near the keyword 'ORDER'. Looks like I can't do an insert with an Order by clause. Here's the code:...
3
by: fran7 | last post by:
Hi, Anyone know how to adjust this so that the results appear in a random order? is it in the "Order By PostCardID DESC" part? ..asp <!--#Include File="art/dbconnect.asp"--> <% ...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.