php - Create multi dimensional array. -


How can I create a database result set in PHP as follows

  Arre ([0] = & gt; Arre ([ID] = & gt; 1 [name] = & gt; Little Heshinda [is_open] = & gt; 0 [order] = & gt; 0) [1] = & gt; Arre ([ID] = & gt; 2 [name] = & gt; Testkat [is_open] = & gt; 0 [order] = & gt; 0) [2] = & Gt; Array ([id] => 3 [name] => fgf [is_open] => [[order] => 0))   

I have the following code,

  $ arr = array (); $ R = mysql_query ("SELECT * FROM categories where id =". $ Key ""); If (mysql_num_rows ($ r)> 0) {$ row = mysql_fetch_assoc ($ r); $ F = mysql_num_rows ($ r); ($ J = 0; $ j & lt; count ($ f); $ j ++) {$ arr [$ j] = $ line [$ f [$ j] ['field']]; }} $ Test = array (); Array_push ($ test, $ arr); Return $ Test;   

but this array returns

  array ([0] => array ([0] => 1 [1] = & Little Helsida [2] => [[3] => 0))   

Any help would be greatly appreciated ..

You can do this:

  $ arr = array (); $ R = mysql_query ( "SELECT * FROM categories WHERE id = '". $ Key "," "); if (mysql_num_rows ($ r) & gt; 0) {$ row = mysql_fetch_assoc ($ r); $ I = 0; while ($ row = mysql_fetch_assoc ($ r)) {$ arr [$ i] = $ row; ++ $ i;}} $ test = array (); Srni_ps ($ test, $ arr); return $ test; < / Code>   

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -