Skip to main content
Commonmark migration
Source Link

I have an SQL query, where i do some joins, but when i var_dump the result in PHP i get an array, with a lot of duplicates. Is there any way to get the result back as an multidimensional array like:

array( array("projectname", "projectdescription", "projectthumb" , "activestate"),
           array("img1.jpg", "img2.jpg", "img3.jpg"),
           array("tech1", "tech2", "tech3") 
         ); 

At the moment i get the following result: http://pastebin.com/ZF7yiafS

The SQL query:

SELECT    p.name,
                              p.description,
                              p.img_thumb,
                              p.active,
                              t.name,
                              i.filename
                    FROM      projects as p
                    JOIN      projects_x_techs as pt
                    ON        p.id = pt.project_id
                    JOIN      techs as t
                    ON        pt.techs_id = t.id
                    JOIN      images as i
                    ON        p.id = i.projects_id
                    WHERE p.slug =  :slug

The ER-diagram ![ER diagram][1] [1]: https://i.sstatic.net/o177R.pngER diagram

I have an SQL query, where i do some joins, but when i var_dump the result in PHP i get an array, with a lot of duplicates. Is there any way to get the result back as an multidimensional array like:

array( array("projectname", "projectdescription", "projectthumb" , "activestate"),
           array("img1.jpg", "img2.jpg", "img3.jpg"),
           array("tech1", "tech2", "tech3") 
         ); 

At the moment i get the following result: http://pastebin.com/ZF7yiafS

The SQL query:

SELECT    p.name,
                              p.description,
                              p.img_thumb,
                              p.active,
                              t.name,
                              i.filename
                    FROM      projects as p
                    JOIN      projects_x_techs as pt
                    ON        p.id = pt.project_id
                    JOIN      techs as t
                    ON        pt.techs_id = t.id
                    JOIN      images as i
                    ON        p.id = i.projects_id
                    WHERE p.slug =  :slug

The ER-diagram ![ER diagram][1] [1]: https://i.sstatic.net/o177R.png

I have an SQL query, where i do some joins, but when i var_dump the result in PHP i get an array, with a lot of duplicates. Is there any way to get the result back as an multidimensional array like:

array( array("projectname", "projectdescription", "projectthumb" , "activestate"),
           array("img1.jpg", "img2.jpg", "img3.jpg"),
           array("tech1", "tech2", "tech3") 
         ); 

At the moment i get the following result: http://pastebin.com/ZF7yiafS

The SQL query:

SELECT    p.name,
                              p.description,
                              p.img_thumb,
                              p.active,
                              t.name,
                              i.filename
                    FROM      projects as p
                    JOIN      projects_x_techs as pt
                    ON        p.id = pt.project_id
                    JOIN      techs as t
                    ON        pt.techs_id = t.id
                    JOIN      images as i
                    ON        p.id = i.projects_id
                    WHERE p.slug =  :slug

The ER-diagram ER diagram

Source Link
Mads K
  • 837
  • 2
  • 14
  • 33

Return MySQL query as multidimensional array

I have an SQL query, where i do some joins, but when i var_dump the result in PHP i get an array, with a lot of duplicates. Is there any way to get the result back as an multidimensional array like:

array( array("projectname", "projectdescription", "projectthumb" , "activestate"),
           array("img1.jpg", "img2.jpg", "img3.jpg"),
           array("tech1", "tech2", "tech3") 
         ); 

At the moment i get the following result: http://pastebin.com/ZF7yiafS

The SQL query:

SELECT    p.name,
                              p.description,
                              p.img_thumb,
                              p.active,
                              t.name,
                              i.filename
                    FROM      projects as p
                    JOIN      projects_x_techs as pt
                    ON        p.id = pt.project_id
                    JOIN      techs as t
                    ON        pt.techs_id = t.id
                    JOIN      images as i
                    ON        p.id = i.projects_id
                    WHERE p.slug =  :slug

The ER-diagram ![ER diagram][1] [1]: https://i.sstatic.net/o177R.png