[PHP] Meerdere checkbox array

Gestart doorShahiem3 reacties41 weergaven

4 berichten · pagina 1 van 1

Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hi,

Ik maak iets waarmee ik gebruikers kan toevoegene in me cms en die kan ik dan permissies geven. Nu haal ik me permissies uit een database en die fetch ik dan.

Voorbeeld:

<tr>
                                <td>Permissies (rechten):</td>
                                <td>
                                    [COLOR= #0000BB]<?php
                                    $permissieQuery[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT
                                                                        id,
                                                                        permissie
                                                                    FROM
                                                                        permissies
                                                                    WHERE
                                                                        verwijderd = 0"[/COLOR][COLOR= #007700]);[/COLOR]
                                                                        
                                    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]num_rows[COLOR= #007700]([/COLOR][COLOR= #0000BB]$permissieQuery[/COLOR][COLOR= #007700]) >=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
                                    {[/COLOR]
                                        
                                        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$permissieFetch[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$permissieQuery[/COLOR][COLOR= #007700]))
                                        {[/COLOR]
                                            
                                            ?>
                                            <input type="checkbox" name="permissie[]" value="[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]entities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$permissieFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]permissie[/COLOR][COLOR= #007700]]);[/COLOR] ?> " /> [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]entities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$permissieFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]permissie[/COLOR][COLOR= #007700]]));[/COLOR] ?> beheren<br />
                                            [COLOR= #0000BB]<?php[/COLOR]
                                            
                                        [COLOR= #007700]}
                                        
                                    }[/COLOR]
                                    [URL="http://www.php.net/else"]else[/URL]
                                    [COLOR= #007700]{[/COLOR]
                                        
                                        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er zijn geen permissies.[/COLOR][COLOR= #007700];
                                        
                                    }[/COLOR]
                                    ?>
                            </tr>


Nu wil ik dat ik in mijn INSERT query alle opties die je hebt gekozen erin kan zetten. Dus hij moet alles ophalen van welke opties je hebt gekozen.

Hoe doe ik dat?

Alvast bedankt.
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Met foreach alle keuzes doorlopen? Of bedoel je hoe je kijkt welke van de mogelijkheden er zijn aangevinkt?
0
Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kijk, ik wil dat hij alles keuzes ophaalt die je gekozen hebt. Maar die moet dan bij de permissies van een lid die wordt aangemaakt.

Bijvoorbeeld dat ik via een variable dan kan ophalen welke keuzes hij heeft gemaakt
0
Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik kijk zo alle checkboxes door:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]optie[/COLOR][COLOR= #007700]])) {[/COLOR]
     
        [COLOR= #0000BB]$optie[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]optie[/COLOR][COLOR= #007700]] AS[/COLOR] [COLOR= #0000BB]$option[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700]){[/COLOR]
        
        [COLOR= #0000BB]$optie[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000],&nbsp;[/COLOR][COLOR= #007700];[/COLOR]
        
        [COLOR= #0000BB]$mogelijkheden[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$optie[/COLOR][COLOR= #007700]);
        
    }[/COLOR]
?>


En de checkboxes zien er zo uit:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Kinderdagverblijf:<input type="checkbox" name="optie[]" value="Kinderdagverblijf" />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;Buitenschoolse opvang:<input type="checkbox" name="optie[]" value="Buitenschoolse opvang" />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;Voorschoolse opvang:<input type="checkbox" name="optie[]" value="Voorschoolse opvang" />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;Tussenschoolse opvang:<input type="checkbox" name="optie[]" value="Tussenschoolse opvang" /><br />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;Naschoolse opvang:<input type="checkbox" name="optie[]" value="Naschoolse opvang" />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;Flexibele dagopvang:<input type="checkbox" name="optie[]" value="Flexibele dagopvang" />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]&nbsp;24-uurs opvang:<input type="checkbox" name="optie[]" value="24-uurs opvang" /><br /><br />[/COLOR][COLOR= #007700];[/COLOR]
?>


PS: Dit was voor een klant van een buitenschoolse opvang, vandaar de opties daarvan smile
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren