how to rotate rows (divs) every page load |
how to rotate rows (divs) every page load |
jimlongo |
Mar 3 2010, 10:47 PM
Post
#1
|
This is My Life Group: Members Posts: 1,128 Joined: 24-August 06 From: t-dot Member No.: 16 |
I have a page with say a dozen items, they could be rows in a table or a series of divs, that's not important at this point.
I want the order of them to be different every time the page loads. Do you have any recommendations as to the best way to achieve that? Thanks, jim |
Brian Chandler |
Mar 3 2010, 11:35 PM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
You mean a "random shuffle"... (your precise stated aim isn't possible, because after 12! showings there is bound to be a repeat !)
Best do it on the server. Next best do it in javascript. Then you provide one fixed order for people with js off. There's something close here: http://imaginatorium.org/ ... but, as I remember now, this is not a _shuffle_ but a random rotation. See yesterday's post about how to randomly shuffle elements, and how not to. |
Christian J |
Mar 4 2010, 07:18 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
your precise stated aim isn't possible, because after 12! showings there is bound to be a repeat ! I think the OP wants all twelve of them to be visible, just in varying order, so the number of combinations should be higher. Seems I've forgotten how to calculate things like that, do you multiply like this: CODE 1*2*3*4*5*6*7*8*9*10*11*12 resulting in 479001600 combinations? |
Brian Chandler |
Mar 4 2010, 09:27 AM
Post
#4
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
your precise stated aim isn't possible, because after 12! showings there is bound to be a repeat ! I think the OP wants all twelve of them to be visible, just in varying order, so the number of combinations should be higher. Seems I've forgotten how to calculate things like that, do you multiply like this: CODE 1*2*3*4*5*6*7*8*9*10*11*12 resulting in 479001600 combinations? Uh, yes. That's what 12! means, it's the normal notation for "12-factorial"... |
jimlongo |
Mar 4 2010, 10:47 AM
Post
#5
|
This is My Life Group: Members Posts: 1,128 Joined: 24-August 06 From: t-dot Member No.: 16 |
Thanks for your answers.
Yes i want all 12, just in different order. Of course eventually there will be repetitions, just that on a daily basis it should resort itself. I've found a javascript method on the Dynamic Drive website that does this randomly on every page load, and have had advice how to make it a daily thing utilizing jQuery. |
Brian Chandler |
Mar 4 2010, 11:14 AM
Post
#6
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Thanks for your answers. Yes i want all 12, just in different order. Of course eventually there will be repetitions, just that on a daily basis it should resort itself. I've found a javascript method on the Dynamic Drive website that does this randomly on every page load, and have had advice how to make it a daily thing utilizing jQuery. I always think using js for things that aren't user-interaction is an ungainly way to do things. Do you mean you want some specific order to last through each 24-hour period? Then it seems vastly easier to compute the day's order once, server-side. Can anyone explain the attraction of javascript for non-user-interactive things? (Other than, I suppose, not having proper server access...) |
Darin McGrew |
Mar 4 2010, 12:24 PM
Post
#7
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
QUOTE Can anyone explain the attraction of javascript for non-user-interactive things? (Other than, I suppose, not having proper server access...) In addition to the issue of server access, I would expect that it's a matter of having a hammer, and therefore thinking that everything looks like a nail. |
Christian J |
Mar 4 2010, 04:42 PM
Post
#8
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
your precise stated aim isn't possible, because after 12! showings there is bound to be a repeat ! I think the OP wants all twelve of them to be visible, just in varying order, so the number of combinations should be higher. Seems I've forgotten how to calculate things like that, do you multiply like this: CODE 1*2*3*4*5*6*7*8*9*10*11*12 resulting in 479001600 combinations? Uh, yes. That's what 12! means, it's the normal notation for "12-factorial"... I see... Sorry for ruining the joke. |
Christian J |
Mar 4 2010, 04:44 PM
Post
#9
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
QUOTE Can anyone explain the attraction of javascript for non-user-interactive things? (Other than, I suppose, not having proper server access...) In addition to the issue of server access, I would expect that it's a matter of having a hammer, and therefore thinking that everything looks like a nail.I see no harm in that if a hammer will do the job. |
Brian Chandler |
Mar 5 2010, 01:35 AM
Post
#10
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
QUOTE Can anyone explain the attraction of javascript for non-user-interactive things? (Other than, I suppose, not having proper server access...) In addition to the issue of server access, I would expect that it's a matter of having a hammer, and therefore thinking that everything looks like a nail.I see no harm in that if a hammer will do the job. Hmm, well I see the smiley, and hesitate, but... there are actually some very important issues here. In mathematics, the "hammer" principle works, perfectly. See the boiling water joke: http://imaginatorium.org/stuff/bubbles.htm Software is mathematical engineering, so _sometimes_ this principle works fine. If execution time isn't a factor, which it often isn't, an incredibly roundabout way of stringing together existing functions may be the most (human-time) efficient way of achieving a particular object. But in general the whole point of engineering is doing things in ways that are robust, and as efficient as reasonably possible. So if on each comparison a screwdriver does a better job than a hammer, it's usually preferable to use a screwdriver. Is javascript easier? No. The algorithms are just about the same. (I couldn't understand the jquery thing about 'daily synchronization', was it? Sounds like doing it on the server as well!) Is javascript more efficient? No. About the same. Is javascript more effective (meaning: percentage of the time that it works)? No, less effective, because n% of clients have js off. This doesn't "matter", because the noscript default offers an unchanging arrangement. Is javascript more reliable (meaning: what are the chances of a bug)? No, less reliable, because once you test the server version, if it works it works for everyone. Even if you prove your javascript correct, implementations may have subtle bugs. (See http://googleresearch.blogspot.com/2006/06...-it-nearly.html ) There is the questionable issue of ridicule if your javascript is wrong (see m$ and "random sorting"), though it is true that for a _sensitive_ bit of code, making it public helps. But that hardly applies here. Hmm... |
Christian J |
Mar 5 2010, 08:17 AM
Post
#11
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
I was thinking that if you already know some javascript you might as well use it rather than learning a whole new language for a single task.
Of course it's hard to gauge things like the probability of bugs in javascript, security holes caused by a server-side script or the work involved in (and/or possible future value of) learning a new language. |
Lo-Fi Version | Time is now: 18th April 2024 - 06:10 PM |