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`.thum bnail LIKE '%-04.%' or `Catalog`.thumb nail LIKE
'%-05.%' or`Catalog`.thu mbnail LIKE '%-03.%' ) and `Catalog`.img_s tatus =
'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 =---- 4 1712
"Jefferis NoSpamme" <je********@hot mail.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
Thanks Dan. I'll think on these options.
Jeff
On 3/8/05 2:35 PM, in article
38************* *@newsread1.new s.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 =----
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_exi sts("randomseed ", $_SESSION)) {
$_SESSION["randomseed "] = time();
}
mysql_query("SE LECT ... ORDER BY RAND($_SESSION[randomseed])");
?>
--
Matt
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#remov e#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_exi sts("randomseed ", $_SESSION)) { $_SESSION["randomseed "] = time(); }
mysql_query("SE LECT ... 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 =---- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 associated with each
entry. Any pointers?
Also, does this bit of code look to be truely random?
def random_number_gen():
winner = ...
|
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 poor man's
DBMS, a broken email server and various other /application/ servers to
try and crack the Internet and IS markets.
In the case where they...
|
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 to expose the
problem:
This post deals with type (2) files.
|
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 generator
(actually i just need binary 1 or 0) i would be forever gratefull ;-)
|
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.
It should put a blue and yellow box on the page with "This is a test" as
part of the picture. But what I get is a broken Gif.
The other problem is...
| |
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
achieve the sort, I'd say the answer is yes. But I don't feel quite confortable
with the intuition... can anyone think of a more solid argumentation ?
|
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:
SELECT @SQLString = N'INSERT INTO TMP_UR_Randoms(Admit_DOCID,
Client_ID, SelectDate, SelectType,RecordChosen)'
SELECT @SQLString = @SQLString +...
|
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"-->
<%
lngCategoryID=CLng(Request("CategoryID"))
If lngCategoryID <> "" And lngCategoryID <> 0 Then
|
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 order, Input field and a submit button.
The Category name is being fetched from the oracle db along with the corresponding Category order.
In...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |