Artenis Posted July 11, 2008 Report Share Posted July 11, 2008 (edited) Lieta principā varētu būt vienkāršāka nekā man liekas, tātad lieta sekojoša: <form method="post" action="?link=1"> <?php $i=1; while($i<11){ ?> <input type="checkbox" name="test[<?php echo $i; ?>]" value="<?php echo $i; ?>"><?php echo 'izvele: '.$i; ?> <?php $i++; } ?> <input type="submit" value="ok"> </form> Man ir pieņēmsim 10 checkboxi: test[1],test[2],test[3].....test[10]. Es izvēlos dažādus no tiem: kaut vai: test[2],test[6],test[7]... Kā panākt, lai uztaisot formai POST, es datubāzēvaru ierakstīt konkrēti izvēlētos. Labākais variants man bija tāds, ka man raksta tik daudz info tabulā cik or to check boxu... tas sanāk, ja man būs 100 checkboxi un es izvēlos 2, tad ierakstīs visus un tos 2 tikai ar dažāām vērtībām. Cerams, ka domu sapratāt! Iepriekš paldies! Edited July 11, 2008 by Artenis Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 A kāpēc tad, tu saglabā DB visus 100, ja tev iečeksēti ir tikai 2 ? Link to comment Share on other sites More sharing options...
Artenis Posted July 11, 2008 Author Report Share Posted July 11, 2008 Es biju domājos tieši atbildi kā ierakstīt tikai tos 2, man kaut kā neiaizet kā vajag kā panākt, ka ieraksta konkrētos gadījumus! Vai nu visus vai nu nevienu man tāsanāk... Ja var tad lūdzu nelielu paraugu! paldies! Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 Kā tu datubāzē viņus glabā ? Ja kā vērtības atdalītas ar komatiem, tad: $str = implode(',', $_POST['test']); Ja atsevišķā "palīgtabulā": foreach($_POST['test'] as $v) { // sql kverijs, kas ievieto tabulā katru $v } Link to comment Share on other sites More sharing options...
Artenis Posted July 11, 2008 Author Report Share Posted July 11, 2008 Milzīgs tev paldies andrisp viss notiek! :) Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 Drīkst zināt kā tu darīji, ka tev nesanāca ? Link to comment Share on other sites More sharing options...
Artenis Posted July 11, 2008 Author Report Share Posted July 11, 2008 nju ok, drīkst: foreach($_POST['pieeja'] as $v) { mysql_query("INSERT INTO $tb5 (gal_id,liet_id)VALUES ('".$_POST['pieeja'][$v]."','$id')"); } Sādi te sanāca! :) Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 Man neinteresēja kādi tev sanāca, bet kā tu mēģināji, kad tev nesanāca. Link to comment Share on other sites More sharing options...
Artenis Posted July 11, 2008 Author Report Share Posted July 11, 2008 Atklāti sakot kauns pat likt, tādēļ labāk nelikšu, jo pats apzinos ka reti glupi mēģināju! :) Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 Nu ok :) Link to comment Share on other sites More sharing options...
xPtv45z Posted July 11, 2008 Report Share Posted July 11, 2008 foreach($_POST['pieeja'] as $v) { .... $_POST['pieeja'][$v] Kas tāds arī strādā? Link to comment Share on other sites More sharing options...
andrisp Posted July 11, 2008 Report Share Posted July 11, 2008 Nu, ja key ir vienāds ar value, tad jā. A jēga ? Link to comment Share on other sites More sharing options...
Artenis Posted July 14, 2008 Author Report Share Posted July 14, 2008 Vēl par šo tēmu. Kā panākt, lai otreiz vienus un tos pašus checkboxus neraksta datubāzē? Paldies. Link to comment Share on other sites More sharing options...
Klez Posted July 14, 2008 Report Share Posted July 14, 2008 paarbaudiit vai jau vinji tur ir :) Link to comment Share on other sites More sharing options...
Artenis Posted July 14, 2008 Author Report Share Posted July 14, 2008 Tik daudz jau es saprotu, tacu... :) if($_POST['pieeja']==""){}else{ foreach($_POST['pieeja'] as $v) { mysql_query("INSERT INTO $tb5 (gal_id,liet_id)VALUES ('".$_POST['pieeja'][$v]."','$id')"); } } Nezinu īsti kāsavienot! Link to comment Share on other sites More sharing options...
Recommended Posts