Jump to content

Calculating streak in table


karimali831

Recommended Posts

Hi,

 

This query will show match stats of a user, the query is the output in the attatchment.

I want to calculate the streak if score1 is greater than score2. So basically, in the attatchment I have selected 3 rows, these 3 rows should be a 3 streak because the user won 3 matches in a row (according to date)

 

SELECT * FROM webs_cup_matches WHERE ladID='17' AND (clan1 != '0' AND clan2 != '0') AND (clan1='2630' || clan2='2630') AND (clan1 != '2147483647' AND clan2 != '2147483647') ORDER BY date DESC

 

any help appreciated.

 

[attachment deleted by admin]

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

That's best done in php, I wouldn't try to express it in SQL.  You can loop through the results from MySQL remembering the following values:

 

1.  How long the current streak is

2.  How long the longest streak was

 

Remember to check at the end (after the loop has finished) to see if the last streak is the longest.

Would you be able to help me out on this please? I'm not familar how to do this with PHP.

If you take a look at the attatchment in my first post, I've explained why the streak should be 3.

 

But not sure how to build this expression.

I'm working on a ladder system project and I'm stuck on this bit (http://team-x1.co.uk/site/index.php?site=standings&ladderID=17) so any help at all, I'll be grateful.

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.