jarvis Posted January 15, 2011 Share Posted January 15, 2011 Hi, I have a structure like so: id | field_id | user_id | value 1 | 1 | 1 | fred smith 2 | 2 | 1 | fred@smith.com 3 | 3 | 1 | 123456 4 | 1 | 1 | joe bloggs 5 | 2 | 1 | joe@bloggs.com 6 | 3 | 1 | 987654 What I'd like to do is return a query like this: fred Smith | fred@smith.com | 123456 joe bloggs | joe@bloggs.com | 987654 I'm just stumped how to do it! Any help is much appreciated. TIA Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/ Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 If that's really your database structure, it really isn't very conducive to, well, much of anything. There's no way to associate what information belongs to which record, from what I can tell. Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1159791 Share on other sites More sharing options...
jarvis Posted January 15, 2011 Author Share Posted January 15, 2011 Thanks Pikachu2000 for the reply. Sadly I'm confined to what's already in place, it's certainly not the way I would have structured it either. I guess the only other way would be pass it to a php array & then explode it out? Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1159806 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 The only suggestion I can make from looking at what's available is (if they all have the same number of records) increment a counter and use its value to indicate where to insert the <br> or </tr><tr> or whatever it is you'll use to format it. Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1159816 Share on other sites More sharing options...
jarvis Posted January 17, 2011 Author Share Posted January 17, 2011 Hi Pikachu2000 That could work but I'm not too sure how i'd go about doing it. Are you able to assist? Thansk Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1160588 Share on other sites More sharing options...
suresh_kamrushi Posted January 17, 2011 Share Posted January 17, 2011 Hi jarvis, You can try this. I think this will solve your problem. SELECT GROUP_CONCAT( value SEPARATOR '|' ) FROM table_name GROUP BY user_id Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1160608 Share on other sites More sharing options...
jarvis Posted January 17, 2011 Author Share Posted January 17, 2011 Thank you suresh_kamrushi , that worked like a charm! Unbelievable, I've spent all weekend trying to solve this, I never knew you could do something so simple! Cheers & a HUGE thank you! Quote Link to comment https://forums.phpfreaks.com/topic/224530-mysql-query-issue/#findComment-1160614 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.