Place multiple similar fields in multi-dimensional array - php mysql -


I want to execute a SQL query such as:

 select 'tb1'. 'F1', 'TB1'. ' F2 ',' TB2 '.' F1 'with' TB1 ',' TB2 '; 

The problem now is that I want to put it in the array in PHP:

 $ result ['tb1'] ['f1'], $ result ['tb1'] [ 'F2'], $ result ['TB2'] ['F1'] ... 

How can one get rid of any idea? Afik does not have any function which is above. I was thinking the easiest way to do this. I do not want to use a query such as "select .. as long as".

I do not already know what the fields will be, so I can not assign them manually as suggested by the answer

You will need to choose, Alec

Lose the data that you are already doing, and then get it in the required format, and Because the fields have similar names, its easiest aliases are to be used or they only return data Overwrite each other (but you can use it for example:

  $ sql = "tb1f1, select tb1.f2 as tb1f2, tb2.TB 1, F1; $ result = mysql_query ($ sql) as TB2 to TB2F1; while ($ line = mysql_fetch_assoc ($ result)) {$ result ['t1'] ['f1'] = $ Line ['tb1f1']; $ result ['t1'] ['f2'] = $ line ['tb1f2']; $ result ['t2'] ['f1'] = $ line ['tb2f1']; }  

(The quote was also incorrect in your SQL)

This will not handle too many rows; But the sequence of your question means that you are the only one expecting a line?

WIthout surname:

  select $ sql = "tb1.f1, tb1.f2, tb2.f1 to tb1, tb2"; $ Result = mysql_query ($ sql); While ($ line = mysql_fetch_row ($ result)) {$ result ['t1'] ['f1'] = $ line [0]; $ Result ['t1'] ['f2'] = $ line [1]; $ Result ['t2'] ['F1'] = $ line [2]; }  

I like the first version as long as you do not have any good reason to use another, because you always change the SQL or add fields as well.

Edit:

Take the meta data into the feedback below ....

   

It looks like what you are doing after that - although you can only get one line at a time.

On an updated array to easily store several rows with another dimension:

Change:

  $ $ [$ Meta [$ key] - & gt; Table] [$ meta [$ of] - & gt; Name] = $ value;  

To:

  $ out [] [$ meta [$ of] - & gt; Table] [$ meta [$ key] - & gt; Name] = $ value;  

Comments