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
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.