karimali831 Posted December 4, 2010 Share Posted December 4, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/ Share on other sites More sharing options...
karimali831 Posted December 6, 2010 Author Share Posted December 6, 2010 anyone can help please or must I re-phrase? Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/#findComment-1143683 Share on other sites More sharing options...
btherl Posted December 7, 2010 Share Posted December 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/#findComment-1143764 Share on other sites More sharing options...
karimali831 Posted December 7, 2010 Author Share Posted December 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/#findComment-1143808 Share on other sites More sharing options...
btherl Posted December 7, 2010 Share Posted December 7, 2010 Are you familiar with using loops to go through results from mysql? Such as "while" and "foreach"? Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/#findComment-1143822 Share on other sites More sharing options...
karimali831 Posted December 7, 2010 Author Share Posted December 7, 2010 yes, I can use use both. Quote Link to comment https://forums.phpfreaks.com/topic/220647-calculating-streak-in-table/#findComment-1143909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.