play_ Posted November 7, 2009 Share Posted November 7, 2009 i have this query select projects.id, projects.type, projects.title, projects.url, uploads.filename from projects inner join uploads on uploads.projectID = projects.id where projects.type = 'lab'" as you can tell it pulls info from projects and uploads table. here's what uploads table look like So both entries relate to the same project. this is what the query returns $result = $sql->query($query); $row = $result->fetchAll(PDO::FETCH_NUM); Array ( [0] => Array ( [0] => 1 [1] => lab [2] => SBR [3] => http://sbr.9leaves.com [4] => 847587269-sbr_1.0__(1).jpg ) [1] => Array ( [0] => 1 [1] => lab [2] => SBR [3] => http://sbr.9leaves.com [4] => 1273681671-sbr_1.0__(2).jpg ) ) it returns 2 sets of results. how can i combine it into one? basically the result array would have 6 elements, the 6th one being the second(or first) screenshot image.... idea result would look like Array ( [0] => Array ( [0] => 1 [1] => lab [2] => SBR [3] => http://sbr.9leaves.com [4] => 847587269-sbr_1.0__(1).jpg [5] => 1273681671-sbr_1.0__(2).jpg ) ) Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/ Share on other sites More sharing options...
mikesta707 Posted November 7, 2009 Share Posted November 7, 2009 have you tried array merge? Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953034 Share on other sites More sharing options...
play_ Posted November 7, 2009 Author Share Posted November 7, 2009 No. but isn't there a way to do it with the query? Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953046 Share on other sites More sharing options...
kickstart Posted November 7, 2009 Share Posted November 7, 2009 Hi Use GROUP BY and GROUP_CONCAT()? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953054 Share on other sites More sharing options...
play_ Posted November 7, 2009 Author Share Posted November 7, 2009 I did try to group by projectID, but that didn't return expected results. will read up on group_contact. thanks Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953363 Share on other sites More sharing options...
play_ Posted November 8, 2009 Author Share Posted November 8, 2009 group_concat joins columns into a single string, so not really what i'm looking for. Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953412 Share on other sites More sharing options...
kickstart Posted November 8, 2009 Share Posted November 8, 2009 Hi As it would seem otherwise you would want a variable number of columns for each row I am not sure how else you could do it. You can always use explode to split up the GROUP_CONCAT column within php. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/180644-solved-simple-sql-query-question/#findComment-953577 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.