FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Shuffle problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Shuffle problem [message #182973 is a reply to message #172196] Mon, 30 September 2013 13:48 Go to previous messageGo to previous message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma:
Senior Member
On 9/30/2013 9:26 AM, richard wrote:
> On my site I want to create a play list that is randomly selected when the
> page is loaded.
> I have ten tables, each with 100 rows.

[sidestepping]
That strikes me as pretty strange database design.
Why do you have 10 tables if they contain the same things?
In case each table represents a year, you might want to add a
year-column to the table, and fill that with the right value.
That way you'll have one clear table.
[end sidestepping]


> I want to extract the first 20 rows from each table.

Ask yourself: What are the FIRST 10 rows?
What "first 10" means depends on your ORDER BY clause.

In general: getting the first 10 is done in a database specific manner.
For example SQL Server:
SELECT TOP 10 FROM sometablename;

In Postgres you'll use: LIMIT and OFFSET

etc.

Look it up for your database.

> Then shuffle that and create the list.
> Somehting similar to shuffling a deck of cards.

Solution: Do 10 selects, each returning 10 rows.
Store them in an array.
OR
Create one query using UNION to glue them together.

Then shuffle it in some way, for example with the shuffle function.

Good luck,
Erwin Moller

>
> So that my playlist might look like:
>
> 1965 #4
> 1963 #13
> 1969 #18
> 1961 #10
> 1960 #3
>
> What ways can I do this?
>


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Help with Security
Next Topic: configuration problem rsyslog with php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 21:33:52 GMT 2024

Total time taken to generate the page: 0.04249 seconds