Jump to content

Calculating streak in table


karimali831

Recommended Posts

Hello

 

Please take a look at attatchment:

 

Lets say for example I wanted to check the streak of clan1 (column) = 9 (rows)

The streak would be 5 because each row has score1 greater than score2.

 

So I want to calculate the streak of the value in clan1 column that has score1 greater than score2 in rows, if score2 is greater than score1 in a row then the streak breaks if that makes sense? let me know if I need to re-phrase.

 

Secondly, if there are two streaks, I want it to calculate the highest one.

 

Thanks for any help !!

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/211345-calculating-streak-in-table/
Share on other sites

On my table the longest streak is only 1, and is outputting this correctly.

And.. I must use a while loop for what I want to achieve?

 

$streak = safe_query("SELECT COUNT(matchID) as streak, clan1 FROM ".PREFIX."cup_matches WHERE clan1='$teamID' AND score1 > score2 GROUP BY clan1 ORDER BY streak DESC LIMIT 1");
while($sk1=mysql_fetch_array($streak)) { $challenger_streak = $sk1['streak']; }

    if(empty($challenger_streak)) $streak = 0;
    else $streak = $challenger_streak;

 

Thanks alot for your help!

You want the max score in score1?

 

SELECT clan1 FROM {$table} ORDER BY score1 DESC LIMIT 1

 

OR,

 

You want the clan with the highest score accumulation in score1?

 

SELECT clan1, SUM(score1) as score FROM {$table} ORDER BY score DESC LIMIT 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.