kasisppr Posted September 19, 2003 Report Share Posted September 19, 2003 Vai PHP ir iespējams veidot daudzdimensionālos masīvus? Mana situācija ir sekojoša - ir tabula ar datiem MySQL datubāzē. Datus savācu šādi - <code><font color="#000000"> $result = mysql_query($query); for ($i=0;$i < mysql_num_rows($result);$i++) { $row = mysql_fetch_array($result);} </font> </code> Taču "iesūcot" datus masīvā, gribētos tos indexēt pēc 2 tabulas kolonu (teiksim id1 un id2) vērtībām un iegūt aptuveni šādu masīvu Masivs [$id1][$id2] = array(colona1, colona2, colona3, ......); Izveidot masīvu ar šīs rindiņas pievienošanu neizdevās <code><font color="#000000"> $masivs [$row["id1"]][$row["id2"]] = $row;</font> </code> Me don't know how to solve the problem. :( Veidot citādi tabulu, vai veidot citu risinājumu. Link to comment Share on other sites More sharing options...
Venom Posted September 19, 2003 Report Share Posted September 19, 2003 varbūt problēma ar array to string conversion? pamēģini: $masiv=array(); $row=mysql_fetch_array($mysql_result); if (!isset($masiv[$row['id1']])) $masiv[$row['id1']]=array(); $masiv[$row['id1']][$row['id2']]=array(); $masiv[$row['id1']][$row['id2']]=$row; Link to comment Share on other sites More sharing options...
Venom Posted September 19, 2003 Report Share Posted September 19, 2003 un jā, es $result = mysql_query($query); for ($i=0;$i < mysql_num_rows($result);$i++) { $row = mysql_fetch_array($result); } dodu priekšroku $result = mysql_query($query); while($row = mysql_fetch_array($result)) { ... } Link to comment Share on other sites More sharing options...
kasisppr Posted September 19, 2003 Author Report Share Posted September 19, 2003 Paldies strādā! :) Link to comment Share on other sites More sharing options...
Recommended Posts