Gossamer Forum
Home : Products : Gossamer Links : Discussions :

build in random order every time?

(Page 1 of 2)
> >
Quote Reply
build in random order every time?
I know you can set the build order/priority of links, but can anyone tell me if it's possible to get the build process to build the links in a 'random' order every time?

Thanks

Quote Reply
Re: build in random order every time? In reply to
Hi,

If you are using mysql 3.23 (which you can tell by entering `select version()` into the SQL monitor), then yes, it's very easy. In the sort order field, simply enter `rand()` as what to sort by. If not, it's much more complex.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: build in random order every time? In reply to
Thanks Alex,

I'm using mysql 3.23 so I tried rand() and it did sort them randomly - but, it started doubling up on a couple of links, and missed a few out. They still made up the right number in total, but some were being replaced by duplicates of others.

Any ideas?

thanx
Regan.

Quote Reply
Re: build in random order every time? In reply to
Hi Regan,

This is very strange, I can't replicate this on my end. Can you send me login info so I can take a look?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: build in random order every time? In reply to
telnet or web? Presuming web?

It seems to be only doubling up when the links span pages.
Quote Reply
Re: build in random order every time? In reply to
mine is 3.22.32
so no solution for me?


Quote Reply
Re: build in random order every time? In reply to
Hi,

If you are using 3.22, you need to:

1. Add a column (FLOAT) called Randomizer to the Links table
2. Set Links SQL to sort by Randomizer
3. Run this query: `UPDATE Links SET Randomizer = RAND()` every time you build the pages.

Hope this helps,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: [ryel01] build in random order every time? In reply to
In Reply To:
I'm using mysql 3.23 so I tried rand() and it did sort them randomly - but, it started doubling up on a couple of links, and missed a few out. They still made up the right number in total, but some were being replaced by duplicates of others.

Hi, i was wondering if this problem is fixed? I have the same problem..

If it's fixed, can someone point me to the soluttion? I searched the forum but can't find it..Unimpressed

Cheers,
Michiel
Quote Reply
Re: [michiel] build in random order every time? In reply to
Hi,

Sorry, upon looking at this closer, you would not be able to get paging to work properly using rand().

You need to use the way described for 3.22 if you have more then one page of results.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] build in random order every time? In reply to
Is there a way to add the UPDATE Links SET Randomizer = RAND() command to nph-build.cgi so that it's done automatically?
Quote Reply
Re: [Jasmine] build in random order every time? In reply to
You can edit nph-build.cgi and add:

$DB->table('Links')->update ( { Randomizer => \'RAND()' });

which would do the update for you.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] build in random order every time? In reply to
We will be breaking up our links into Priority, New, and The Rest of Them

Priority will be displayed first, then New, then The Rest.

Is there a way to have The Rest sorted randomly, but leave the others sorted by Title?

We want the last group to get all mixed around each build.

In fact, we might even want to do random sortings of each group within itself.

So, for example, we might still show the Priority group first, then the New group, then The Rest, but the links within the Priority Group could be sorted randomly, then the New group could be alpha, then The Rest could be random. That could be neat.

Thanks muchly.

------------------------------------------
Quote Reply
Re: [Alex] build in random order every time? In reply to
Works like a charm -- thanks! Smile
Quote Reply
Re: [Alex] build in random order every time? In reply to
In Reply To:
You can edit nph-build.cgi and add:

$DB->table('Links')->update ( { Randomizer => \'RAND()' });

Alex, I can't seem to get this to work in nph-build.cgi. I'm running SQL 3.22 and when I insert the above line into the Repair Tables or Build All sub nothing happens to the Randomizer number for the Links.

Is the code above missing a SET command? Also, where would you recommend putting it in nph-build?

It works fine when I run this query: `UPDATE Links SET Randomizer = RAND()` in the SQL Monitor.

Thanks,

Bryan

Last edited by:

BryanL: Oct 1, 2002, 6:29 AM
Quote Reply
Re: [BryanL] build in random order every time? In reply to
Wouldn't jsut editing the sort order be enough? Something like;

ID RAND, Title DESC, URL DESc

etc

Crazy

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] build in random order every time? In reply to
That would sort the links by the random number, but since the random number doesn't change it would always be sorted the same way, which defeats the purpose.

What I'm trying to do is automate the process of assigning new random numbers to the Randomize field, so that each time I re-build the site Links will generate a new random number for each link.

Bryan
Quote Reply
Re: [BryanL] build in random order every time? In reply to
Erm, why would it always be the same random number? the RAND() function is built into MySQL, so theoretically it should be different each time Unsure

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] build in random order every time? In reply to
In Reply To:
Erm, why would it always be the same random number? the RAND() function is built into MySQL, so theoretically it should be different each time Unsure

Hmm.. Apparently it's not working with my install of Links as I get an error message when I try to sort using RAND.

"Can't call method "fetchall_hashref" on an undefined value at /cgibin/admin/Links/User/Search.pm line 147."

I'm using MySQL 3.22 which doesn't have the random sort ability, would that affect the RAND function that's built into Links?

At any rate, I don't think that would do what I want it to do. I normally want results sorted by Title, but some people have paid extra for a Featured Link. I display Featured Lists in various places throughout my site and would like those lists to be sorted randomly.

Also, like the above posts, sometimes those lists will span more than one page, and I would like to avoid duplicates. By creating a new field, Randomizer, and sorting by that it works perfectly as long as I remember to refresh the Randomizer number using SQL Monitor every time I do a build. It would be even more perfect if that was automated in some way.

Bryan
Quote Reply
Re: [BryanL] build in random order every time? In reply to
Quote:
I'm using MySQL 3.22 which doesn't have the random sort ability, would that affect the RAND function that's built into Links?

The RAND function isn't built into links, it is a mysql function, so yes it won't work.
Quote Reply
Re: [Alex] build in random order every time? In reply to
Hi,

I can get this to work in the SQL monitor, but where do I place this in nph-build? I've tried everything!

$DB->table('Links')->update ( { Randomizer => \'RAND()' });

Thanks for the help!

marc
Quote Reply
Re: [hcom] build in random order every time? In reply to
I use this and place it on nph-build.cgi just before:

sub main {

This works for my Links installation so that the order of the links are random on each rebuild (when the sorting is set up to sort by Randomizer.

--Frank
Quote Reply
Re: [FrankM] build in random order every time? In reply to
It must have something to do with the fact that my SQL version is 3.22 because using the above command in nph-build yields no result. I can run the proper query in SQL Monitor with great success, but something about that syntax doesn't seem to work with nph-build. Anyone have any insight?

thanks!

marc
Quote Reply
Re: [hcom] build in random order every time? In reply to
Actually, I use the following on nph-build.cgi:

$DB->table('Links')->update ( { Randomizer => \'RAND() * 20' });

This makes Randomizer a number between 0 and 20. I don't know if this will affect things for you. (When I tried it on mine without multiplying by 20, then I got the value '0' for all instances of Randomizer).

--Frank
Quote Reply
Re: [FrankM] build in random order every time? In reply to
Frank,

Thanks again for posting. What version of mysql are you running? I'm at 3.22 and it really must have something to do with the syntax as to why I can't get it to function. I've placed this in my nph-build:

$DB->table('lsql_Links')->update ( { Randomizer => \'RAND() * 20' });

sub main {
# -------------------------------------------------------------------



note that "lsql_Links" is the name of my table entry.

it's so frustrating!

marc
Quote Reply
Re: [hcom] build in random order every time? In reply to
Hi Marc,

I think you shouldn't include the prefix with your table entry. I also have a prefix for my Links tables, but it isn't used on nph-build.cgi. Try it again without the "lsql_" prefix, and I think it should work. (You do need to use the prefix in SQL Monitor though).

--Frank

Last edited by:

FrankM: Mar 28, 2003, 10:26 AM
> >