Shadowing Posted April 9, 2013 Share Posted April 9, 2013 (edited) Hey guys having issues trying to get group_concat to work. If its even what im looking for All these columns are INT accept bombers which is a string What I want to do is also add each bombers columns with a - seperator "SELECT SUM(naqahdah) , COUNT(*) , SUM(slaves) , SUM(jaffa) , SUM(unas) , SUM(resources) , SUM(death_gliders), SUM(threaders) , GROUP_CONCAT(bombers separator '-') , SUM(staff_cannons) , SUM(naqahdah_mines) FROM planets WHERE id= $user_id GROUP BY id"; If anyone could kindly help Edited April 9, 2013 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/ Share on other sites More sharing options...
Barand Posted April 9, 2013 Share Posted April 9, 2013 If we knew what your table looks like, and we knew what you were trying to output, we might stand a chance Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423703 Share on other sites More sharing options...
Shadowing Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) Thanks for teh reply Barand bombers look like 50000-5000-45600-54369 I need the return to end up in the same pattern when adding all the bombers columsn up where id equals user_id Edited April 9, 2013 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423709 Share on other sites More sharing options...
Barand Posted April 9, 2013 Share Posted April 9, 2013 If bombers looks like that then GROUP_CONCAT is working perfectly. And my previous statement still stands. If I don't know what you have and want I cannot help Sorry. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423717 Share on other sites More sharing options...
Shadowing Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) I'm unsure where your confusion lies Barand I need mysql to return in the same pattern when all bombers rows are being added together so bombers row1 looks like '50-6-7-8-3-4-5' bombers row2 looks like '50-6-7-8-3-4-5' bombers row3 looks like '50-6-7-8-3-4-5' i need the return to be '50-6-7-8-3-4-5-50-6-7-8-3-4-5-50-6-7-8-3-4-5' Edited April 9, 2013 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423725 Share on other sites More sharing options...
Shadowing Posted April 9, 2013 Author Share Posted April 9, 2013 I figured out my issue almost. apparently i have to set a Alias to grab from it so GROUP_CONCAT(bombers separator '-') as bombers Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423726 Share on other sites More sharing options...
Shadowing Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) my return looks like this now 50000---50000-50000-50000-50000-- my columns do look exactly like this '50-6-7-8-3-4-5' not sure where these extra - are coming from Edited April 9, 2013 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423727 Share on other sites More sharing options...
Shadowing Posted April 9, 2013 Author Share Posted April 9, 2013 I figured out its cause of my null values on some rows. Not sure how to get around that so it ignores null rows Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423735 Share on other sites More sharing options...
Solution Shadowing Posted April 9, 2013 Author Solution Share Posted April 9, 2013 Alright I solved my problem using IFNULL GROUP_CONCAT(NULLIF(bombers,'') separator '-') AS bombers Thanks for the amazing help you provided Barand you are a true saint to this forum of phpfreaks.com Quote Link to comment https://forums.phpfreaks.com/topic/276722-problem-using-group_concat/#findComment-1423736 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.