Mapster Skrevet 20. juni 2005 Del Skrevet 20. juni 2005 Jeg har ett skjema som inneholder ca.900 "checkbox'er", som sendes videre til ett php script som skal registrere det i en mysql database. Spørsmålet mitt er om det er noen som helts måte å registrere og lagre disse i databasen ved å kjøre en loop? Feltene er navngitt slik: p1, p2, p3, p4...p898, p899, p900. Lenke til kommentar
PT Skrevet 20. juni 2005 Del Skrevet 20. juni 2005 (endret) Du kan lage et array av skjemaene: <input type="checkbox" name="p[]" value="1"> <input type="checkbox" name="p[]" value="2"> Om jeg ikke husker helt feil vil du da få et array som ser sånn ca slik ut: array( 1 => "on", 2 => "off", ); Såfremt du har krysset av boks nummer 1. Fra manualen: How do I create arrays in a HTML <form>? To get your <form> result sent as an array to your PHP script you name the <input>, <select> or <textarea> elements like this: <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> Notice the square brackets after the variable name, that's what makes it an array. You can group the elements into different arrays by assigning the same name to different elements: <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyOtherArray[]" /> <input name="MyOtherArray[]" /> This produces two arrays, MyArray and MyOtherArray, that gets sent to the PHP script. It's also possible to assign specific keys to your arrays: <input name="AnotherArray[]" /> <input name="AnotherArray[]" /> <input name="AnotherArray" /> <input name="AnotherArray[phone]" /> The AnotherArray array will now contain the keys 0, 1, email and phone. Note: Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form. Our first example will contain keys 0, 1, 2 and 3. Endret 20. juni 2005 av PT Lenke til kommentar
Mapster Skrevet 20. juni 2005 Forfatter Del Skrevet 20. juni 2005 Takker... Jeg viste det var noe med array's eller no sånt.. Jeg er ikke helt proff i php ennå, mest c++ som er min ting. Lenke til kommentar
Loomy Skrevet 20. juni 2005 Del Skrevet 20. juni 2005 En liten notis som muligens ikke spiller noen rolle, mener å huske at en uavkrysset checkboc returnerer '' (tom), ikke "off". "on" er derimot riktig. Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå