Blink Posted February 19, 2014 Report Share Posted February 19, 2014 Vārdusakot ir šāda lieta: $result3 = mysql_query("SELECT * FROM table WHERE `adder` = '$ids'") or die(mysql_error()); $vertiba = array(); while($row3 = mysql_fetch_array($result3)){ ?> <td style='width:0px;'> <select name="vardi[<? echo $row3['id'];?>]"> <option value="4">----</option> <option value="1">Brauca 100%</option> <option value="2">Brauca 50%</option> <option value="4">Nebija</option> </select> </td> <? $KK = $row3['id']; $vertiba[$KK] = $row3['vards'] . " " . $row3['uzvards']; } if(isset($_POST['add'])){ foreach($_POST['vardi'] as $kid => $value){ $array = array( "name" => $vertiba[$kid], "option" => $value ); } var_dump($array); $add = serialize($array); $laiks2 = $_POST['date2']; mysql_query("DB INSERT"); } Problēma tāda, ka vajadzētu būt 4 cilvēkiem, kurus viņš arī nolasa no DB viss okey, līdz brīdim, kad vajag ievadīt datus. ievietojot datus parāda, ka viss okey, bet viņš ievieto TIKAI viena cilvēka vārdu uzvārdu un viņa value.. Kā panākt lai ievieto visu cilvēku vārdus un viņu value.. ? Izvadu šādi - >echo implode( ', ' , unserialize($row3['brauceji']) ); Quote Link to comment Share on other sites More sharing options...
php newbie Posted February 19, 2014 Report Share Posted February 19, 2014 īpaši neiedziļinajos, bet tu ciklā masīvam katru reizi piešķiri jaunu vērtību, bet vajag likt klāt.$array[] = ... vaiarray_push($array, $value); Quote Link to comment Share on other sites More sharing options...
Blink Posted February 19, 2014 Author Report Share Posted February 19, 2014 Uzliekot $array[] =uzmet erroru izvadot:Warning: implode(): Invalid arguments passed in Kapēc tā?? Quote Link to comment Share on other sites More sharing options...
Blink Posted February 19, 2014 Author Report Share Posted February 19, 2014 var_dump parāda šo array(4) { [0]=> array(2) { ["name"]=> string(13) "Inita Valguma" ["option"]=> string(1) "4" } [1]=> array(2) { ["name"]=> string(13) "Sintija Zirne" ["option"]=> string(1) "4" } [2]=> array(2) { ["name"]=> string(20) "Sintija Vēverbrante" ["option"]=> string(1) "4" } [3]=> array(2) { ["name"]=> string(14) "Indulis Zirnis" ["option"]=> string(1) "4" } } Bet outputāWarning: implode(): Invalid arguments passed Quote Link to comment Share on other sites More sharing options...
jurchiks Posted February 19, 2014 Report Share Posted February 19, 2014 implode nevar implodēt nested masīvus... Quote Link to comment Share on other sites More sharing options...
Blink Posted February 19, 2014 Author Report Share Posted February 19, 2014 implode nevar implodēt nested masīvus... Tavs risinājums? Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted February 19, 2014 Report Share Posted February 19, 2014 foreach($array as $value) echo implode(', ', $value); Quote Link to comment Share on other sites More sharing options...
Blink Posted February 20, 2014 Author Report Share Posted February 20, 2014 foreach($array as $value) echo implode(', ', $value); Tas izskatās, kā? kka nesanāk. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted February 21, 2014 Report Share Posted February 21, 2014 Nu johaidī, kas tu masīvu nemāki izvadīt? echo '<pre>'; print_r($array); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted February 21, 2014 Report Share Posted February 21, 2014 echo '<pre>',var_dump($array),'</pre>'; lol Quote Link to comment Share on other sites More sharing options...
jurchiks Posted February 21, 2014 Report Share Posted February 21, 2014 var_dump nav tik smuks, IMHO. Quote Link to comment Share on other sites More sharing options...
Blink Posted February 21, 2014 Author Report Share Posted February 21, 2014 (edited) a:4:{i:0;a:2:{s:4:"Name";s:13:"Inita Valguma";s:6:"Option";s:1:"1";}i:1;a:2:{s:4:"Name";s:13:"Sintija Zirne";s:6:"Option";s:1:"1";}i:2;a:2:{s:4:"Name";s:14:"Indulis Zirnis";s:6:"Option";s:1:"1";}i:3;a Inputs izskatās šāds, pievēršat uzmanību pašam sākumam, man šķiet, ka tur ir kļūda. BET šobrīd kods izskatās šādi $result3 = mysql_query("SELECT * FROM table WHERE `adder` = '$ids'") or die(mysql_error()); $vertiba = array(); while($row3 = mysql_fetch_array($result3)){ ?> <td style='width:0px;'> <select name="vardi[<? echo $row3['id'];?>]"> <option value="4">----</option> <option value="1">Brauca 100%</option> <option value="2">Brauca 50%</option> <option value="4">Nebija</option> </select> </td> <? $KK = $row3['id']; $vertiba[$KK] = $row3['vards'] . " " . $row3['uzvards']; } if(isset($_POST['add'])){ foreach($_POST['vardi'] as $kid => $value){ $array[] = array( "Persona" => $vertiba[$kid], "Value" => $value, ); } var_dump($array); $add = serialize($array); $laiks2 = $_POST['date2']; mysql_query("DB INSERT"); } Edited February 21, 2014 by Blink Quote Link to comment Share on other sites More sharing options...
kasisppr Posted February 21, 2014 Report Share Posted February 21, 2014 Nu tats ir labi, kad tev tagad ir cits kods, bet tu saproti, ka tev $add = serialize($array); ir jau cits neka pirms tam. Iespējams tev ir jādara kaut kas līdzīgs $laiks2 = $_POST['date2']; foreach($array AS $sub_array) { $add = serialize($sub_array); mysql_query("DB INSERT"); // ???? neesi neko strukturali noradijis, tapec nevaru te palidzet } Quote Link to comment Share on other sites More sharing options...
Blink Posted February 21, 2014 Author Report Share Posted February 21, 2014 Nu tats ir labi, kad tev tagad ir cits kods, bet tu saproti, ka tev $add = serialize($array); ir jau cits neka pirms tam. Iespējams tev ir jādara kaut kas līdzīgs $laiks2 = $_POST['date2']; foreach($array AS $sub_array) { $add = serialize($sub_array); mysql_query("DB INSERT"); // ???? neesi neko strukturali noradijis, tapec nevaru te palidzet } Azigāja, bet ja mysql insert ir iekš foreach, tad viņš pievieno katru cilvēku atsevišķi.. Ja mysql insert ir ārpus foreach tad tikai pedējā cilvēka vārdu uzvārdu un value.. :/ Quote Link to comment Share on other sites More sharing options...
Blink Posted February 22, 2014 Author Report Share Posted February 22, 2014 Itkā dabuju pie dziesmas, lai ieiveito vienā reizē visus. $v4 = array(); foreach($array AS $sub_array) { $v4[] = $sub_array; } $add = serialize($v4); $laiks2 = $_POST['date2']; mysql_query("INSERT INTO `plani_list` (`id`, `vaditajs`,`date`,`date2`, `adder`, `brauceji`) VALUES ('', '$vaditajs', '$laiks', '$laiks2', '$ids', '$add' )"); Bet tikai array,array,array,array :D Kāds nezin kapēc tā? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.