Note that there are some explanatory texts on larger screens.

plurals
  1. POchange the format of the array returned from a sql stored procedure
    primarykey
    data
    text
    <p>I don't even know if what I would like is possible but here you go: I have a stored procedure returning an array with all the data I need but not in the format that I would like: I have </p> <p>a table <code>USER</code></p> <p>a table <code>TYPE</code></p> <p>a table <code>USER_TYPE (foreign key user_id from USER, type_id from TYPE)</code></p> <p>a table <code>GAME</code></p> <p>a table <code>USER_GAME (foreign key user_id from USER, game_id from GAME)</code></p> <p>And I have a query with JOINS:</p> <pre><code>SELECT user_name,type_name,game_name FROM user u INNER JOIN user_type ut ON u.user_id=ut.user_id INNER JOIN type t ON ut.type_id=t.type_id LEFT JOIN user_game ug ON u.user_id=ug.user_id INNER JOIN game g ON ug.game_id=g.game_id WHERE t.type_name = ? ... </code></pre> <p>So I get an array in the following format:</p> <pre><code>[0] =&gt; Array ( [user_id] =&gt; 1 [type] =&gt; type1 [game] =&gt; game1 ) [1] =&gt; Array ( [user_id] =&gt; 1 [type] =&gt; type1 [game] =&gt; game2 ) [2] =&gt; Array ( [user_id] =&gt; 1 [type] =&gt; type2 [game] =&gt; game2 ) </code></pre> <p>etc...</p> <p>but I would like the query to return an array such as</p> <pre><code>[0] =&gt; Array ( [user_id] =&gt; 1 [type] =&gt; type1 [game1] =&gt; game1 [game2] =&gt; game2 ) [1] =&gt; Array ( [user_id] =&gt; 1 [type] =&gt; type2 [game1] =&gt; game1 [game2] =&gt; game2 ) </code></pre> <p>etc...</p> <p>Thus listing all the games for one user in each array: I guess I would need to basically keep the join on type, get the various user_id from it and then get the games for each of those various user_id, and kind of merge all that. That would be great if that could be done inside the procedure itself.</p> <p>I hope that wasn't unreadable, would be very grateful for any help. By the way if any of you could direct me towards good tutorials about more advanced sql queries 'cause I'm a bit short on that... Thank you very much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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