anonīms Posted November 13, 2008 Report Share Posted November 13, 2008 Tātad tiek ievadīti dati, kur dažiem no tiem ir jauzliekas pašiem no sevis. ir lauks tips un tas var būt 1. kuka 2. aka 3. kaka 4. smaka 5. vel_kaut_kas tabulā kurā tos ievietos arī ir kollonas 1.koll1 2.koll2 3.koll3 4.koll4 Kā izveidot, lai ievietojot datus viņi tiktu ievietoti RANDOMā (jautkā secībā) kā arī, lai viņi neatkārtotos? Link to comment Share on other sites More sharing options...
bubu Posted November 13, 2008 Report Share Posted November 13, 2008 1) saliec visus datus masīvā 2) masīvam pielieto shuffle funkciju 3) elementus ņem no masīvā ārā pēc kārtas un liec atbilstošajos laukos iekšā Link to comment Share on other sites More sharing options...
anonīms Posted November 13, 2008 Author Report Share Posted November 13, 2008 (edited) $test = array('de_dust2'=>1,'de_nuke'=>2,'de_inferno'=>3,'de_train'=>4,'de_cpl_mill'=>5,'de_cbble'=>6); $numbers = range(1, 6); srand((float)microtime() * 1000000); shuffle($numbers); foreach ($numbers as $number) { echo "$number "; } tikai kā man to $test iesmērēt tajā $numbers = range? vnk snuffle($test) ? ok, thx. Dabuju gatavu $test = array('de_dust2'=>1,'de_nuke'=>2,'de_inferno'=>3,'de_train'=>4,'de_cpl_mill'=>5,'de_cbble'=>6); srand((float)microtime() * 1000000); shuffle($test); foreach ($test as $number) { echo "$number "; } Edited November 13, 2008 by anonīms Link to comment Share on other sites More sharing options...
bubu Posted November 13, 2008 Report Share Posted November 13, 2008 srand ir lieki izsaukt. php to automātiski dara. Īsti nesaprotu arī tava masīva jēgu.. Tev šādi neder? $test = array('de_dust2', 'de_nuke', 'de_inferno', 'de_train', 'de_cpl_mill', 'de_cbble'); xshuffle($test); foreach ($test as $number) { echo "$number "; } Link to comment Share on other sites More sharing options...
anonīms Posted November 14, 2008 Author Report Share Posted November 14, 2008 (edited) šķiet, ka der. Bet vienīgi man viņi jāieivieto datubāzē un tad es nezinu kā īsti viņus visus apvienot zem viena kverija. ja man ir šie 1/2/3 tad varu foreach ($test as $number=>$aa) { mysql_query("UPDATE <tabula> SET map".$aa." = ".$number.""); } jo man vienā tabulā ir map1 līdz map6 Edited November 14, 2008 by anonīms Link to comment Share on other sites More sharing options...
bubu Posted November 14, 2008 Report Share Posted November 14, 2008 Nu tad kamdēļ tev vispār tos nosaukumus vajag? $numbers = range(1, 6); shuffle($numbers); foreach ($numbers as $number) { echo "$number "; } Link to comment Share on other sites More sharing options...
anonīms Posted November 14, 2008 Author Report Share Posted November 14, 2008 (edited) Tomēr izdariju savādāk, izrādas, ka jā. Man tos skaitļus nemaz nevajag. $kartes_random = array( 'de_dust2', 'de_nuke', 'de_inferno', 'de_train', 'de_cpl_mill', 'de_cbble' ); shuffle($kartes_random); $nr = 1; foreach ($kartes_random as $number) { $karshu_kverijs = "UPDATE gamefarm_turniri SET map".$nr++." = '".$number."' WHERE id = $turnira_id"; mysql_query($karshu_kverijs); Viss iet. Edited November 14, 2008 by anonīms Link to comment Share on other sites More sharing options...
Recommended Posts