eevan79 Posted October 1, 2010 Share Posted October 1, 2010 Here is my code: SELECT *, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, ($scoreFormula) as totalscore FROM ( SELECT gp.name as name, bans.name as banname, avg(dp.courierkills) as courierkills, avg(dp.raxkills) as raxkills, avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills, avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills, count(*) as totgames, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins, SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans on bans.name = gp.name WHERE dg.winner <> 0 GROUP BY gp.name having totgames >= $games) as i ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage As you can see I am using AVG to get users average data and all in one query. I also need to find when users left the game and count this as disconnects. There is table gameplayers (as gp. in code above)and when user left before the game ends, leftreason filed is"Disconnected" or "ECONNRESET". So it need to add this code, but I always get error. MAX(...code to select table...WHERE (`leftreason` LIKE('%ECONNRESET%') OR `leftreason` LIKE('%was dropped%') ) ) Is this even possible? Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/ Share on other sites More sharing options...
Adam Posted October 1, 2010 Share Posted October 1, 2010 This query looks a mess. I haven't wrapped my head around it properly yet, but the DK ratio case statement- aren't you repeating the logic? The sub-query already works out the ratio and returns it as "killdeathratio". Assuming we can remove that, you then have ($scoreFormula) as totalscore - you're injecting a variable into the query so that you can select it? That makes no sense. Assuming we can remove that, you're then just selecting * from a sub-query. Remove the outer query then and you have a simpler query to deal with. Add some indentation and you're left with: SELECT gp.name as name , bans.name as banname , avg(dp.courierkills) as courierkills , avg(dp.raxkills) as raxkills , avg(dp.towerkills) as towerkills , avg(dp.assists) as assists , avg(dp.creepdenies) as creepdenies , avg(dp.creepkills) as creepkills , avg(dp.neutralkills) as neutralkills , avg(dp.deaths) as deaths , avg(dp.kills) as kills , count(*) as totgames , case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio , SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins , SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans ON bans.name = gp.name WHERE dg.winner <> 0 GROUP BY gp.name having totgames >= $games ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage Does this work? Probably be easier for you to edit in future if so. To your original question, where are you wanting to add that SQL? Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118018 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 Yes this code is working, but I dont have score formula...and I needed. Current score formula: $scoreFormula = '((((kills-deaths+assists*0.5+towerkills*0.5+raxkills*0.2+(courierkills+creepdenies)*0.1+neutralkills*0.03+creepkills*0.03) * .2)+(wins-losses)))*10'; If I change scoreFormula users will get different score. But I can use that formula after fetching data from sql. Regarding to your question...I want to count data from gameplayers (gp) table where users disconnected or dropped from game (as disconnect) gp.leftreason LIKE('%ECONNRESET%') OR gp.leftreason LIKE('%was dropped%') O have tried this: LEFT JOIN gameplayers as disconnects ON (gp.leftreason LIKE('%ECONNRESET%') OR gp.leftreason LIKE('%was dropped%')) But, of course, its not working. Can I add it to this query? Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118032 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 Correction: your code is not working: MySQL Error: 1064 ( You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' bans.name as banname , avg(dp.courierkills) as courierkills , avg(dp.raxk' at line 3) Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118046 Share on other sites More sharing options...
kickstart Posted October 1, 2010 Share Posted October 1, 2010 Hi Can't see what is causing the error you are getting. However to get the extra data I think we need more info. What is the structure of gp? Are there multiple records there for a single game / player and you want to count the number of disconnects for that game player? Or are you only interested in disconnected games? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118055 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 Ok, before I answer you look at this code: SELECT *, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, ($scoreFormula) as totalscore FROM ( SELECT gp.name as name, bans.name as banname, avg(dp.courierkills) as courierkills, avg(dp.raxkills) as raxkills, avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills, avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills, COUNT(*) as totgames, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins, SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses SUM(case when( (gp.`leftreason` LIKE ('%ECONNRESET%')) OR (gp.`leftreason` LIKE ('%was dropped%')) ) then 'DISC' ) as disc FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans on bans.name = gp.name WHERE dg.winner <> 0 $_sql GROUP BY gp.name having totgames >= $games) as i ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage I separated "wrong" code between empty lines. This error occured: MySQL Error: 1064 ( You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SUM(case when( (gp.`leftreason` LIKE ('%ECONNRESET%')) OR (gp.`le' at line 33) In gp there is data for one single user (who joined the game): id, gameid, name, left, leftreason, team, color etc... I want to match leftreason with ECONNRESET or was dropped and count it as disconnets from all games. Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118060 Share on other sites More sharing options...
awjudd Posted October 1, 2010 Share Posted October 1, 2010 I believe that the syntax error you just provided us with is because you are missing the comma between losses and SUM ... i.e. SELECT *, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, ($scoreFormula) as totalscore FROM ( SELECT gp.name as name, bans.name as banname, avg(dp.courierkills) as courierkills, avg(dp.raxkills) as raxkills, avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills, avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills, COUNT(*) as totgames, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins, SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses , SUM(case when( (gp.`leftreason` LIKE ('%ECONNRESET%')) OR (gp.`leftreason` LIKE ('%was dropped%')) ) then 'DISC' ) as disc FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans on bans.name = gp.name WHERE dg.winner <> 0 $_sql GROUP BY gp.name having totgames >= $games) as i ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118066 Share on other sites More sharing options...
kickstart Posted October 1, 2010 Share Posted October 1, 2010 Hi Looks like you are trying to SUM a character result there (rather than converting disconnects to 1 and others to 0 and summing that). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118067 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 Ok, I'l separate problematic code: then 1 else 0 end) as losses , SUM(case when( (gp.`leftreason` LIKE ('%ECONNRESET%')) OR (gp.`leftreason` LIKE ('%was dropped%')) ) then 1 else 0 end) as disc FROM gameplayers as gp Now I get values 1 or 0 instead of SUM. This large code totally confused me. Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118073 Share on other sites More sharing options...
ngreenwood6 Posted October 1, 2010 Share Posted October 1, 2010 I briefly reviewed your code but couldnt you take some of the processing out of that query and just do the processing via php. Most of the time you can and can save you a big headache of trying to figure out complex queries. Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118089 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 I can only remove killdeathratio ratio and calcualte it with php. If I remove more coding then I need to prepare aditional queries for that. With this code I have all data about users from 5 different tables. Also, this code is used for highscore list. Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118120 Share on other sites More sharing options...
kickstart Posted October 1, 2010 Share Posted October 1, 2010 Now I get values 1 or 0 instead of SUM. This large code totally confused me. To answer this I think I need the full table declarations and a few sample lines. However you are looking at the gp table and joining other tables to it. This could result in multiple rows for the same gp row, in which case you SUM would be the sum of the duplicated rows which are disconnected (which doesn't seem useful to me). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118128 Share on other sites More sharing options...
eevan79 Posted October 1, 2010 Author Share Posted October 1, 2010 I know that data, in this case, can be populated better in mysql, but that depence of hosting program (which is used to insert data into mysql). Here is samples and tables: dotagames (dg) INSERT INTO `dotagames` (`id`, `botid`, `gameid`, `winner`, `min`, `sec`) VALUES (31, 0, 32, 0, 0, 0), (30, 0, 31, 0, 0, 0), (29, 0, 30, 2, 53, 48), (28, 0, 29, 2, 53, 18), (27, 0, 28, 1, 53, 19); ...etc. dotaplayers (dp) INSERT INTO `dotaplayers` (`id`, `botid`, `gameid`, `colour`, `kills`, `deaths`, `creepkills`, `creepdenies`, `assists`, `gold`, `neutralkills`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `hero`, `newcolour`, `towerkills`, `raxkills`, `courierkills`) VALUES (1, 0, 1, 2, 2, 3, 22, 1, 2, 0, 0, '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 'Hvsh', 3, 0, 0, 0), (2, 0, 1, 3, 1, 1, 7, 0, 0, 2, 0, '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 'N016', 9, 0, 0, 0), (3, 0, 1, 5, 0, 2, 5, 0, 1, 18, 0, '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 'U000', 5, 0, 0, 0), (4, 0, 1, 10, 11, 3, 46, 1, 2, 2, 9, '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 'UC42', 10, 0, 0, 0), (5, 0, 1, 9, 9, 5, 219, 1, 10, 2, 37, 'I099', 'I06B', 'I0AW', 'I0A9', 'I0A8', 'I0A1', 'U00K', 8, 2, 0, 0); ...etc gameplayers (gp) INSERT INTO `gameplayers` (`id`, `botid`, `gameid`, `name`, `ip`, `spoofed`, `reserved`, `loadingtime`, `left`, `leftreason`, `team`, `colour`, `spoofedrealm`) VALUES (1, 0, 1, 'sVeTiDjOkA', '91.150.116.97', 1, 0, 12656, 626, 'has left the game voluntarily', 0, 3, 'europe.battle.net'), (2, 0, 1, 'adida_s', '77.66.157.119', 1, 0, 9453, 1068, 'has left the game voluntarily', 0, 2, 'europe.battle.net'), (3, 0, 1, 'BuBi.Mr_PoRn', '84.132.243.78', 1, 0, 13078, 718, 'has left the game voluntarily', 0, 5, 'europe.battle.net'), (4, 0, 1, 'changer4', '194.170.95.210', 1, 0, 34844, 1763, 'has left the game voluntarily', 0, 4, 'europe.battle.net'), (5, 0, 1, 'DsD)WitE(', '86.149.188.238', 1, 0, 7984, 3655, 'has left the game voluntarily', 1, 8, 'europe.battle.net'), (6, 0, 1, 'Neubivljiv', '192.168.1.5', 1, 1, 7828, 3977, 'has left the game voluntarily', 0, 1, ''), (7, 0, 1, 'Dirty-Tool', '91.49.241.117', 1, 0, 25328, 2795, 'has left the game voluntarily', 1, 11, 'europe.battle.net'), (8, 0, 1, 'Loucien', '79.103.98.165', 1, 0, 15859, 2818, 'has left the game voluntarily', 1, 10, 'europe.battle.net'), (9, 0, 1, 'shernat', '77.65.107.184', 1, 0, 22500, 3696, 'has left the game voluntarily', 1, 9, 'europe.battle.net'), (10, 0, 1, 'Xalaropsolis', '79.103.121.80', 1, 0, 7984, 3983, 'has left the game voluntarily', 1, 7, 'europe.battle.net'), (11, 0, 2, 'Ricky.Boy', '86.124.133.233', 1, 0, 8375, 30, 'has left the game voluntarily', 0, 4, 'europe.battle.net'), (12, 0, 2, 'Human_From_MARS', '87.126.10.162', 1, 0, 7031, 61, 'has lost the connection (connection error - ECONNRESET)', 1, 10, 'europe.battle.net'), (13, 0, 2, 'Neubivljiv', '93.87.149.182', 1, 1, 9391, 189, 'has left the game voluntarily', 0, 1, 'europe.battle.net'); ...etc games INSERT INTO `games` (`id`, `botid`, `server`, `map`, `datetime`, `gamename`, `ownername`, `duration`, `gamestate`, `creatorname`, `creatorserver`) VALUES (1, 0, 'europe.battle.net', 'MapsDownloadDotA Allstars v6.60b.w3x', '2009-06-26 13:27:33', 'dota -sdso!!! ghost!', 'Neubivljiv', 3983, 16, 'Neubivljiv', ''), (2, 0, 'europe.battle.net', 'MapsDownloadDotA Allstars v6.60b.w3x', '2009-06-26 17:10:19', 'dota -sdso ghost++ !!!', 'Neubivljiv', 189, 16, 'Neubivljiv', 'europe.battle.net'), (3, 0, 'europe.battle.net', 'MapsDownloadDotA Allstars v6.60b.w3x', '2009-06-26 18:24:43', 'dota sdso! ghost++', 'Neubivljiv', 73, 16, 'Neubivljiv', 'europe.battle.net'), (4, 0, 'europe.battle.net', 'MapsDownloadDotA Allstars v6.60b.w3x', '2009-06-26 21:53:24', 'dota -sdso ghost!!!', 'Neubivljiv', 2790, 16, 'Neubivljiv', ''), (5, 0, 'europe.battle.net', 'MapsDownloadDotA Allstars v6.60b.w3x', '2009-06-27 00:10:48', 'dota -sdso!!! ghost!!!', 'Neubivljiv', 3037, 16, 'Neubivljiv', ''); And data from code (first post) can be viewed here Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118147 Share on other sites More sharing options...
kickstart Posted October 2, 2010 Share Posted October 2, 2010 Hi If I understand it, gameplayers has one row for per / game. A player will not have multiple rows for the same game? Your code gets you the details of a players games, and the extra column you want is the number of disconnections that player has had in any game. If so something like this:- SELECT gp.name as name , bans.name as banname , avg(dp.courierkills) as courierkills , avg(dp.raxkills) as raxkills , avg(dp.towerkills) as towerkills , avg(dp.assists) as assists , avg(dp.creepdenies) as creepdenies , avg(dp.creepkills) as creepkills , avg(dp.neutralkills) as neutralkills , avg(dp.deaths) as deaths , avg(dp.kills) as kills , count(*) as totgames , case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio , SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins , SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses , SUM(case when((gp.`leftreason` LIKE ('%ECONNRESET%')) OR (gp.`leftreason` LIKE ('%was dropped%'))) then 1 else 0 end) as disc FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans ON bans.name = gp.name LEFT JOIN gameplayers as gp2 ON gp.name = gp2.name WHERE dg.winner <> 0 GROUP BY gp.name having totgames >= $games ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118265 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 Ok, I hope we are almost done. With your code I get an error: MySQL Error: 1054 ( Unknown column 'totalscore' in 'order clause') I have added totalscore and then I got one huge query (delay) before top players page displayed. For now this code is working: SELECT *, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, ($scoreFormula) as totalscore FROM ( SELECT gp.name as name, bans.name as banname, avg(dp.courierkills) as courierkills, avg(dp.raxkills) as raxkills, avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills, avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills, SUM(dp.kills) as totkills, SUM(dp.deaths) as totdeaths, COUNT(*) as totgames, case when (kills = 0) then 0 when (deaths = 0) then 1000 else ((kills*1.0)/(deaths*1.0)) end as killdeathratio, SUM(case when(((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as wins, SUM(case when(((dg.winner = 2 and dp.newcolour < 6) or (dg.winner = 1 and dp.newcolour > 6)) AND gp.`left`/ga.duration >= $minPlayedRatio) then 1 else 0 end) as losses , SUM( (gp.`leftreason` LIKE ('%has lost the connection%')) OR (gp.`leftreason` LIKE ('%was dropped%')) OR (gp.`leftreason` LIKE ('%Lagged out%')) OR (gp.`leftreason` LIKE ('%Dropped due to%')) ) as disc FROM gameplayers as gp LEFT JOIN dotagames as dg ON gp.gameid = dg.gameid LEFT JOIN dotaplayers as dp ON dg.gameid = dp.gameid AND gp.colour = dp.colour AND dp.newcolour <> 12 AND dp.newcolour <> 6 LEFT JOIN games as ga ON dp.gameid = ga.id LEFT JOIN bans on bans.name = gp.name WHERE dg.winner <> 0 $_sql GROUP BY gp.name having totgames >= $games) as i ORDER BY $order $sortdb, name $sortdb LIMIT $offset, $rowsperpage I have added more maches to see result. And then I got disconnects, but not same number when I click on each user (user details). There is same query for lefreason, just for specific user. For example on top page for one player I see 1 disc, when I click on user details I can see 4. This is query for single user - user info page (for disconnects) SELECT COUNT(*) FROM `gameplayers` WHERE (`leftreason` LIKE('%has lost the connection%') OR `leftreason` LIKE('%was dropped%') OR `leftreason` LIKE('%Lagged out%') OR `leftreason` LIKE('%Dropped due to%') ) AND name= '$username' LIMIT 1 Here is 2 screenshots (taken from top page, and for user info) (user disc marked with red color.) Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118273 Share on other sites More sharing options...
fenway Posted October 2, 2010 Share Posted October 2, 2010 It's impossible to debug sql statements with placeholder variables.; Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118378 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 Yes...finally I debug it. Problem is WHERE dg.winner <> 0 So this query is only for wins and losses. 0 means DRAW. And thats why other disc arent counted. I totally forgot that this query ignore unfinished/uncompleted games. So many headaches .... and always turns out to be a simple problem. Quote Link to comment https://forums.phpfreaks.com/topic/214914-more-data-from-mysql-complex-query/#findComment-1118393 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.