I've a site where companies add their article.
I'de like to provide a "lasts articles" table. By this, I'll show last
articles inserted. But I won't always the same articles at any refresh.
Question 1: how to get a "random" selection from the database, giving more
priority to the last inserted (the ones with higher articleID)
Question 2: I'd like to provide one article by client. I won't show 3
articles from the same client only because he has been the last one to
insert his articles.
So I must randomly select by choosing between last articleID, but only one
per clientID.
simplified table is:
articleID
clientID
details
price.
It is possible with MySQL ? or any idea how to achieve this ?
PS:I've no access to mysql NG.
BOB 3 2009
Bob Bedford wrote:
Hi Bob, I've a site where companies add their article.
I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh. Question 1: how to get a "random" selection from the database, giving more priority to the last inserted (the ones with higher articleID)
Do that in PHP and not in SQL.
I don't know if it is possible in SQL, but it sounds like a monsterquery to
me.
How to approach?
If you have all your articleid present in the database CONTINIOUSLY (no gaps
caused by deleting records), I think you can relatively conjure up some
algoritm that will produce one of the articleid's.
The excact formula depends on the distribution you want, of course.
How much bigger must the chance be for recent articles?
If you have gaps between the articleid's, I suggest you first get them in
ORDER BY articleid, and add indexnumbers to them in some array, like
1 articleid = 2
2 articleid = 3
3 articleid = 5
4 articleid = 9
etc
Then use the indexnumbers for the distribution.
(If you have trouble conjuring up some formula, ask here again)
Question 2: I'd like to provide one article by client. I won't show 3 articles from the same client only because he has been the last one to insert his articles.
So I must randomly select by choosing between last articleID, but only one per clientID.
I would also do this in PHP and not in SQL.
use ORDER BY clientid, articleid in your query, and loop over the result,
picking a random articleid PER clientid simplified table is:
articleID clientID details price.
It is possible with MySQL ? or any idea how to achieve this ?
PS:I've no access to mysql NG.
EVERYBODY has access to mySQL.
You can download it right now.
:-) BOB
Regards,
Erwin Moller
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> a écrit dans
le message de news: 42************* ********@news.x s4all.nl... Bob Bedford wrote:
Hi Bob,
I've a site where companies add their article.
I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh. Question 1: how to get a "random" selection from the database, giving more priority to the last inserted (the ones with higher articleID)
Do that in PHP and not in SQL. I don't know if it is possible in SQL, but it sounds like a monsterquery to me.
How to approach? If you have all your articleid present in the database CONTINIOUSLY (no gaps caused by deleting records), I think you can relatively conjure up some algoritm that will produce one of the articleid's.
The excact formula depends on the distribution you want, of course. How much bigger must the chance be for recent articles?
If you have gaps between the articleid's, I suggest you first get them in ORDER BY articleid, and add indexnumbers to them in some array, like 1 articleid = 2 2 articleid = 3 3 articleid = 5 4 articleid = 9 etc
Then use the indexnumbers for the distribution.
(If you have trouble conjuring up some formula, ask here again)
Question 2: I'd like to provide one article by client. I won't show 3 articles from the same client only because he has been the last one to insert his articles.
So I must randomly select by choosing between last articleID, but only one per clientID.
I would also do this in PHP and not in SQL. use ORDER BY clientid, articleid in your query, and loop over the result, picking a random articleid PER clientid
simplified table is:
articleID clientID details price.
It is possible with MySQL ? or any idea how to achieve this ?
PS:I've no access to mysql NG.
EVERYBODY has access to mySQL. You can download it right now. :-)
Hi Erwin,
Thanks for suggestions.
I have a huge database, quering like you say will have a huge load on the
server.
I've seen MySQL allow to use RANDOM and subquery.
I think I must mix those things for doing that. The purpose of doing that is
to avoid to return 1000 results then thread only 5 of them. If the server
may returns directly the 5 items, it would just be great, and I'm sure it's
possible.
select distinct ClientID from client order by reverse(RAND()) LIMIT 0,5)
//get 5 different clients
Then for each client:
select distinct articleID from article where article.ClientI D =
client.ClientID order by reverse(RAND()) LIMIT 0,1
This should work even if I haven't tested yet. The problem is that it
doesn't really select the last articles, it just select any random article
from any random client. I've a field called lastdatetime in the article
table. It does log the last modification datetime. I'd like to use this
value to get the best result, but actually don't know how.
Bob
>> PS:I've no access to mysql NG. EVERYBODY has access to mySQL. You can download it right now.
MYSQL NEWSGROUP (NG).
Also missing something before.
The main purpose is to track the preferred article the user is looking for.
Then provide a more appropriate offer for his need.
Takes this example:
For a computer hardware store.
At the first visit, I provide randomly article from the last entered, from
the various providers.
Then I see that the user is looking for a flat screen (by the search
engine): Here I show a more appropriate choice of randomly selected
articles, not getting them only randomly, but selecting them between flat
screens only. That's the purpose of what I'm looking for.
Bob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: RobertoP |
last post by:
Hello,
I am trying to create a simple Oracle application that queries some data
from Oracle. The problem is that it randomly returns trailing \0s instead of
the characters of a string.
Instead of:
NIC, returns sometimes as N\0\0
188524C-01, returns somtimes as 18852\0\0\0\0\0
|
by: sbatschelet |
last post by:
I am running into a really odd problem with Access and looking for some
insight as to what could be causing my issue. Basically this SQL
creates a listing of Total Sales (Sum(InvLine.Retail)) by Category
(InvLine.Cat) which seems strait forward. But today I run the report
and a category is doubled, so I went through the basic steps of...
|
by: TPK |
last post by:
I have an HTML document with Javascript where I have a portion of the
page contents, a series of questions, being pulled from a XML file.
When the page dynamically builds all the questions and selection
choices are listed top down in the order they appear in the XML file.
Here is an example of the XML formatting:
<question...
|
by: tjbvo |
last post by:
Greetings
I am busy with a program that randomly selects data from a databse and then populates controls with the random data. the user must then select an option that must be stored for printing at the end of the program.
Below I have pasted my code. I am using VB6 and MSAccess Database.
Thanking You in Advance.
Julian
|
by: tamaker |
last post by:
Is this do-able with ASP / VBscript?
-- I have a database with user records (name, photo, etc. etc.)
I want to use asp to generate (on the homepage) a series of 4 randomly
selected 'user records' from the database -- say just the headshot
photo or name from the database.
In addition to the recordset being randomly generated (i.e. our of...
| |
by: camarun20 |
last post by:
Hi ,
I constructed an MS access query in java to retrieve the rows in random.
The code snipet
Connection con = DriverManager.getConnection( database ,"","");
Statement s = con.createStatement()
strQry = "select top 10 S_No , Rnd(S_No) as exp from Questions order by Rnd(S_No) desc" ;
s.execute(strQry) ;
|
by: Man4ish |
last post by:
I have one pblm for reading a file randomly for searching the value with in given range.
e.g.
offset allele id
19 G/T 2066803
20 C/T 2066804
13 A/G 2066805
12 A/G 2066927
In the above file i have to search all the records which are in range (10,15). If i read...
|
by: programmerx101 |
last post by:
Ok, I'm looking for expert advice on this one.
I have a database which keeps going into read_only mode. Sometimes it goes into read_only / single user mode. Once it was taken offline completely. This seemingly happens randomly. Out of all of the database I have worked with, this has happened on 3 of them - several times randomly to each. All...
|
by: ezechiel |
last post by:
I've been looking for this on the forum, but didn't find anything in relation with excel.
So, I have cells with text, from A3 -> A159
And I need to select 50% (or 25% or 12.5%) of these cells randomly.
I also need a function to select 10 cells randomly.
Anyone has an idea how I could do this?
|
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |