Re: [PHP] Sort problem

2011-09-14 Thread Igor Escobar
Wow!

Thank you! I completely forgot this method!


Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar 





On Wed, Sep 14, 2011 at 12:02 PM, Marc Guay  wrote:

> > Anyone know a smart way to order file names?
>
> Nope, but I know a "natural" way:
> http://ca.php.net/manual/en/function.natsort.php
>


Re: [PHP] Sort problem

2011-09-14 Thread Marc Guay
> Anyone know a smart way to order file names?

Nope, but I know a "natural" way:
http://ca.php.net/manual/en/function.natsort.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Sort problem

2011-09-14 Thread Igor Escobar
Hi Folks!

Anyone know a smart way to order file names?

An example to you guys picture what im saying is:



The result of this snippet is:

Array
(
[0] => Two And Half Man Season 1[1] => Two And Half Man Season
10[2] => Two And Half Man Season 2
[3] => Two And Half Man Season 3
[4] => Two And Half Man Season 4
[5] => Two And Half Man Season 9

)

Anyone knows how to solve this problem?


Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar 


Re: [PHP] sort problem

2002-07-11 Thread Analysis & Solutions

On Thu, Jul 11, 2002 at 11:30:16AM +0200, andy wrote:
> 
> Table 1 user_table
> id
> points
> 
> Table 2 reports
> report_id
> user_id
> rating
> 
> The goal is to associate every user extra 50 points if he has a top 10
> report.
> Top 10 report means the 10 reports with the highest ranking. This value is
> always changing, thats why I did not include it to the other points.
> Now that we have the users with the additional points we could add them to
> the total points of the user and then find out the 5 users with the highest
> total points.

There are probably a couple ways to do this.  This is the one that hits me
off the top of my head, assuming you're using a version of MySQL which
can't do subqueries.

Now, all of this is untested, so my query syntax may be off a tad, but 
it'll give you the idea of where to go...

Do the following intermittently on a scheduled basis:

1) Make a third table.  It'll hold temporary data.
 user_id
 totalscore
2) LOCK TABLES Table3 READ
3) DELETE FROM Table3 WHERE 1=1
4) INSERT INTO Table3 (user_id, totalscore) SELECT user_id, 20 AS sc
 FROM Table2 ORDER BY rating LIMIT 10
5) INSERT INTO Table3 (user_id, totalscore) SELECT id, points
 FROM Table1
6) UNLOCK TABLES

Now, whenever you want to generate the top 5 list use the following query
   SELECT user_id, SUM(totalscore) AS thescore FROM Table3
   GROUP BY user_id ORDER BY SUM(totalscore) LIMIT 5

If you can create subqueries, then you don't need the third table and can 
write one nice query, something like this...

SELECT id, sc+points AS totalscore FROM Table1
LEFT JOIN (SELECT user_id, 20 AS sc FROM Table2 ORDER BY rating LIMIT 10)
ON (Table1.id = Table2.user_id)
ORDER BY sc+points LIMIT 5

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort problem

2002-07-11 Thread Justin French

"If he has a top-ten report"... is that a one-off thing?  Or is it a weekly
thing?  Or is that every time his report get's into the top ten (in which
case hovering around 10-11 would be the best bet!!)??

You need to decide WHEN the user is awarded the 50 points for being in the
top ten.

For example, if this was judged weekly, then you could write a small script
which is run weekly, awarding 50 points to the user_id's in the top 10
ratings... easy, but what happens to the guy who had something in there for
Sun-Thur, and you run the job on Friday?  Not good.

Or perhaps the points are awarded each time the top 10 changes... can't
imagine why!!  Yuk!

Or maybe you can only be awarded the 50 points ONCE, the FIRST time you're
in the top ten, in which case, I'd add a 4th field to Table "reports",
flagging it as "once a top ten", and apply the 50 points at that point.


Like I said, you need to define when this happens, so that we can figure out
the best way... or perhaps you'll figure it out for yourself after you have
a think about WHEN the 50 points are applied.


Justin French



on 11/07/02 7:30 PM, andy ([EMAIL PROTECTED]) wrote:

> ok here we go:
> 
> Table 1 user_table
> id
> points
> 
> Table 2 reports
> report_id
> user_id
> rating
> 
> The goal is to associate every user extra 50 points if he has a top 10
> report.
> Top 10 report means the 10 reports with the highest ranking. This value is
> always changing, thats why I did not include it to the other points.
> Now that we have the users with the additional points we could add them to
> the total points of the user and then find out the 5 users with the highest
> total points.
> 
> Thats the theory, but how to achieve this in real live??
> 
> Thanx for any idas,
> 
> Andy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort problem

2002-07-11 Thread andy

ok here we go:

Table 1 user_table
id
points

Table 2 reports
report_id
user_id
rating

The goal is to associate every user extra 50 points if he has a top 10
report.
Top 10 report means the 10 reports with the highest ranking. This value is
always changing, thats why I did not include it to the other points.
Now that we have the users with the additional points we could add them to
the total points of the user and then find out the 5 users with the highest
total points.

Thats the theory, but how to achieve this in real live??

Thanx for any idas,

Andy

"Analysis & Solutions" <[EMAIL PROTECTED]> schrieb im
Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Please post the relevant table and field names.
>
> --Dan
>
> --
>PHP classes that make web design easier
> SQL Solution  |   Layout Solution   |  Form Solution
> sqlsolution.info  | layoutsolution.info |  formsolution.info
>  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort problem

2002-07-10 Thread Analysis & Solutions

Please post the relevant table and field names.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort problem

2002-07-10 Thread Chris Hewitt

Ed, Andy

Andy said that the points were in the users table. Table layouts would 
have been useful. It sounds to me as though the users table has not got 
its points up to date and needs updating from the scores table first. 
Then do the select on just the users table.

My 2p (pence, I'm in the UK so we're not in the Dollar or Euro zone, yet!)

Chris

Lazor, Ed wrote:

>I'm not sure if I completely understand what you're asking, but
>
>It sounds like one table has user information.  The second table has a
>record for each user and a field for the total number of points of each
>user.  Something like this:
>
>Users (Table 1)
>-
>ID
>Name
>Address
>etc.
>
>Scores (Table 2)
>-
>ID
>UserID
>Points
>
>
>If this isn't the case, well, you'll probably want to adjust your database
>structure.  This approach allows you to do a simple SQL query like this:
>
>select Users.*, Scores.* from Users, Scores where Users.ID = Scores.UserID
>ORDER BY Scores.Points limit 5
>
>
>
>
>-Original Message-
>From: andy [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, July 10, 2002 10:52 AM
>To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
>Subject: [PHP] sort problem
>
>
>Hi guys,
>
>I have a problem sorting values comming out of a db. It is not as easy.
>
>Here is the prob:
>One table containing user points.
>Other table containing reports with rankings
>For each top 10 report (the 10 reports with the most ranking) there are 20
>extra points granted
>
>Now I would like to get the top 5 members out of the db. If I only pull out
>the user table ordered by points desc limit 5 I might miss a user with a top
>10 report and 20 extra points.
>
>So I thought about sorting the array afterwards with asort, but then I loose
>the asoziation with the user_id.
>
>Maybe there is a way to sort the other arrays with the same sorting algo? Or
>a way to include a iff clause in the query?
>
>currently I am doing:
>SELECT
>u_name,
>id,
>points
>FROM user
>WHERE
>points > 0
>ORDER by points desc
>LIMIT 5
>
>and the top10 reports extra.
>
>Has anybody a good idea on that?
>
>Andy
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] sort problem

2002-07-10 Thread Lazor, Ed

I'm not sure if I completely understand what you're asking, but

It sounds like one table has user information.  The second table has a
record for each user and a field for the total number of points of each
user.  Something like this:

Users (Table 1)
-
ID
Name
Address
etc.

Scores (Table 2)
-
ID
UserID
Points


If this isn't the case, well, you'll probably want to adjust your database
structure.  This approach allows you to do a simple SQL query like this:

select Users.*, Scores.* from Users, Scores where Users.ID = Scores.UserID
ORDER BY Scores.Points limit 5




-Original Message-
From: andy [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 10, 2002 10:52 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP] sort problem


Hi guys,

I have a problem sorting values comming out of a db. It is not as easy.

Here is the prob:
One table containing user points.
Other table containing reports with rankings
For each top 10 report (the 10 reports with the most ranking) there are 20
extra points granted

Now I would like to get the top 5 members out of the db. If I only pull out
the user table ordered by points desc limit 5 I might miss a user with a top
10 report and 20 extra points.

So I thought about sorting the array afterwards with asort, but then I loose
the asoziation with the user_id.

Maybe there is a way to sort the other arrays with the same sorting algo? Or
a way to include a iff clause in the query?

currently I am doing:
SELECT
u_name,
id,
points
FROM user
WHERE
points > 0
ORDER by points desc
LIMIT 5

and the top10 reports extra.

Has anybody a good idea on that?

Andy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
 

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] sort problem

2002-07-10 Thread andy

Hi guys,

I have a problem sorting values comming out of a db. It is not as easy.

Here is the prob:
One table containing user points.
Other table containing reports with rankings
For each top 10 report (the 10 reports with the most ranking) there are 20
extra points granted

Now I would like to get the top 5 members out of the db. If I only pull out
the user table ordered by points desc limit 5 I might miss a user with a top
10 report and 20 extra points.

So I thought about sorting the array afterwards with asort, but then I loose
the asoziation with the user_id.

Maybe there is a way to sort the other arrays with the same sorting algo? Or
a way to include a iff clause in the query?

currently I am doing:
SELECT
u_name,
id,
points
FROM user
WHERE
points > 0
ORDER by points desc
LIMIT 5

and the top10 reports extra.

Has anybody a good idea on that?

Andy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php