mounkuls Posted November 7, 2008 Report Share Posted November 7, 2008 foreach ir masīviem. while ir cikliem kamēr nosacījums true. Link to comment Share on other sites More sharing options...
anonīms Posted November 8, 2008 Author Report Share Posted November 8, 2008 mounkuls, bet tāpat print_r($_POST); viņiem vajadzēja izvadīties. Mēģināšu darīt tā, lai tas viss nav pasplēpts zem <div id=""></td> Link to comment Share on other sites More sharing options...
anonīms Posted November 19, 2008 Author Report Share Posted November 19, 2008 Ceļu augšā topiku! Tātad: http://paste.php.lv/8485?lang=php izvadot print_r ir Array ( [kills_1c] => kapteinis [deaths_1c] => kapteinis [kills_tm1] => Array ( [0] => 15 [1] => 17 ) [deaths_tm1] => Array ( [0] => 3 [1] => 2 ) [kills_2c] => kaka [deaths_2c] => sua [kills_tm2] => Array ( [0] => 2 ) [deaths_tm2] => Array ( [0] => 13 ) [add_overview_end] => Next >> ) un Warning: Invalid argument supplied for foreach() in ap_players_overview.php on line 16 16 - foreach rinda. Lauks nav tukšs... Redzat, ar post viņš izvada tikai vienu kills_tm1 un tas pats ir array. Kur varētu būt vaina? Link to comment Share on other sites More sharing options...
bubu Posted November 19, 2008 Report Share Posted November 19, 2008 Kurā tad vietā tajā masīvā ir "kills_tm1[]" atslēga? Es tur redzu "kills_tm1" bez nekādām [] Link to comment Share on other sites More sharing options...
anonīms Posted November 19, 2008 Author Report Share Posted November 19, 2008 Hmm, bet inputā viss ir kā vajag. <input type='text' name='kills_tm1[]' size='1' /> Link to comment Share on other sites More sharing options...
marcis Posted November 19, 2008 Report Share Posted November 19, 2008 (edited) Tu savā print_r`ā redzi $_POST['kills_tm1[]'] šito? EDIT: Paskaidrošu dziļo domu - tev nepareizs $_POST mainīgais norādīts foreach`ā. Spiežot pēc print_r un tā, ko tu padod foreach`am, php ļoti pareizi met vārnu. Edited November 19, 2008 by marcis Link to comment Share on other sites More sharing options...
anonīms Posted November 19, 2008 Author Report Share Posted November 19, 2008 (edited) tur viss ir pareizi # foreach($_POST['kills_tm1[]'] as $kills_tm1) { echo "Kills: ".$kills_tm1."<br />"; } Edited November 19, 2008 by anonīms Link to comment Share on other sites More sharing options...
andrisp Posted November 19, 2008 Report Share Posted November 19, 2008 anonīms, nu taču noņem to [] nost. :) Link to comment Share on other sites More sharing options...
marcis Posted November 19, 2008 Report Share Posted November 19, 2008 Ja būtu pareizi, tad strādātu (: Link to comment Share on other sites More sharing options...
anonīms Posted November 20, 2008 Author Report Share Posted November 20, 2008 (edited) foreach($_POST['kills_tm1'] as $kills_tm1) { echo "Kills: ".$kills_tm1." ID: ".$_POST['p1id']."<br />"; // tikai testējam pagaidām bez kverija. } Tik tālu nu būtu pareizi :) Vēl tikai pēdējais, lai pareizi ievietotu kverijā echo "<tr><td><strong>".$speletaja_vards['1']."</strong><input type='hidden' value='".$speletaja_vards['0']."' name='p1id[]' /></td><td>Kills: <input type='text' name='kills_tm1[]' size='1' /></td><td>Deaths: <input type='text' name='deaths_tm1[]' size='1' /></td></tr>"; Kvērijam vajag update <table> set kills = kills WHERE id = $_POST['p1id'], bet kā lai to p1id dabū, jo man viņš tikai vienu izvelk. Ideāls variants būtu, ja varētu foreach($_POST['kills_tm1'] as $kills_tm1 AND $_POST['p1id'] as $p1id) bet tādu lietu neatļauj :( Ko šeit varētu izmantot? Edited November 20, 2008 by anonīms Link to comment Share on other sites More sharing options...
marcis Posted November 20, 2008 Report Share Posted November 20, 2008 šis $_POST['p1id'] tev arī ir masīvs? Ja šis ir pareizi, tad tāpat arī būvē kveriju foreach($_POST['kills_tm1'] as $kills_tm1) { echo "Kills: ".$kills_tm1." ID: ".$_POST['p1id']."<br />"; // tikai testējam pagaidām bez kverija. } Link to comment Share on other sites More sharing options...
anonīms Posted November 20, 2008 Author Report Share Posted November 20, 2008 Izmet array tavam kodam marcis. Šādi viss iet foreach($_POST['playerid_tm1'] as $p1id) { echo "ID: ".$p1id."<br />"; // playerid_tm1 ir tas pats, kas p1id } Bet kā tagad viņus apvienot zem viena kverija (foreach)..? Link to comment Share on other sites More sharing options...
marcis Posted November 20, 2008 Report Share Posted November 20, 2008 Tev jāpanāk, ka $_POST['playerid_tm1'] un $_POST['kills_tm1'] katram vērtību pārim ir viena atslēga. Tad varēsi izvēlēties jebkuru masīvu, kuru ciklēt un ar atslēgu dabūt vajadzūgo vērtību no otra masīva. Nezinu kā paskaidrot vēl "primātiskāk". Praktiski tas izskatītos kautkā tamlīdzīgi: foreach($_POST['kills_tm1'] as $key=>$value){ echo 'Kills: '.$value.' ID: '.$_POST['playerid_tm1'][$key]; } Link to comment Share on other sites More sharing options...
anonīms Posted November 21, 2008 Author Report Share Posted November 21, 2008 Jap, tā arī izveidoju. Viss iet. Link to comment Share on other sites More sharing options...
Recommended Posts