473,287 Members | 1,659 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,287 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 1703

"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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.