Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL (or PHP?) group results by field data
    text
    copied!<p>I have a MySQL database that looks similar to this:</p> <pre><code>ID Group Name 1 1 John 2 1 Andrea 3 1 Jack 4 2 Mike 5 2 Kurt 6 3 Alice </code></pre> <p>I need to sort the results in a html table that looks like this:</p> <pre><code>Group Name ----------------------- 1 John Andrea Jack ----------------------- 2 Mike Kurt ----------------------- 3 Alice ----------------------- </code></pre> <p>I don't know if this should be done with a SQL query (concat_group, or something similar) or with PHP, can somebody please help me out?</p> <p>Guys, thanks for the help below, but I also need to accomplish something similar, like this:</p> <pre><code>ID meta_key meta_value name 1 group 1 John 2 group 1 Andrea 3 group 1 Jack 4 group 2 Mike 5 group 2 Kurt 6 group 3 Alice </code></pre> <p>and I need to sort / display the same as the example above, something like this:</p> <pre><code>group name ----------------------- 1 John Andrea Jack ----------------------- 2 Mike Kurt ----------------------- 3 Alice ----------------------- </code></pre> <p>Now my problem has taken new dimensions. My database looks like:</p> <pre><code>b.ID b.meta_key b.meta_value a.title 1 group 1 Title 1 2 group 1 Title 2 3 group 1 Title 3 4 group 2 Title 4 5 group 2 Title 5 6 group 3 Title 6 7 coef 6 Title 1 8 coef 4 Title 2 9 coef 12 Title 3 9 coef 2 Title 4 9 coef 3 Title 5 9 coef 7 Title 6 </code></pre> <p>(I'm working with to tables)</p> <p>And I need to achieve:</p> <pre><code>group title coef --------------------------------- 1 Title 1 6 Title 2 2 Title 3 12 -------------------------------- 2 Title 4 2 Title 5 3 -------------------------------- 3 Title 6 7 -------------------------------- </code></pre> <p>¿Is this even possible?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload