Handle Multiple Check Boxes?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Handle Multiple Check Boxes?

    I have a PHP generated page which displays X many records. Each record has
    a checkbox preceding it. The user checks several checkboxes, and hits a
    delete button. All the corresponding records will be deleted.

    But I'm running into difficulty...


    Right now the NAME property of each check box is the primary key of the
    corresponding record. Hence if I know which checkboxes are checked, I
    simply use DELETE using the NAME value.

    Generally speaking, how do I get the server side to see which check boxes
    were checked?

    The check box names may not be sequential, if any records have been deleted
    previously, and the first check box might be a number greater than 0.

    Is there an easy mechanism to do this? Some kind of built in cnotrol array
    allowing me to loop over every check box that was on the form submitted?

    I could store the last and first checkbox number in a hidden input, then
    loop starting/ending at those values, but that may loop over a lot of
    controls that do not exist.


    Thoughts?



    <Ade
    --
    Adrian Parker. Ordained priest. <adrian.parker@sympatico.ca>

    "A society that views graphic violence as entertainment ...should not be
    surprised when senseless violence shatters the dreams of it's youngest and
    brightest..." - Ensign (March 2004)


    Adrian Parker Guest

  2. Similar Questions and Discussions

    1. Inserting Check Boxes
      I NEED HELP! PLEASE! Ill explain best I can.. here is what I got: I need to use check boxes so a user can select/deselect the ingrediants they...
    2. CFMail & Check Boxes
      I'm sure this question has been asked and answered before but I couldn't find it the forum. Sorry about that. I'm looking for a work around to the...
    3. Check Boxes
      Fmpro 5.5 Windows XP pro I have a number field set up as a checkboxes, numbered from 11 to 18. I had a script that used to check all the boxes...
    4. P. S. re check boxes
      I can only export this in a filtered web page. That's the only option I am given. If these alignment problems are due to that aspect, how do I...
    5. Check to see if Check Boxes are Checked
      How do I check to see if a checked box is check on the following page? This is what I have. What am I doing wrong? <%If...
  3. #2

    Default Re: Handle Multiple Check Boxes?

    Adrian Parker wrote:
    > I have a PHP generated page which displays X many records. Each record has
    > a checkbox preceding it. The user checks several checkboxes, and hits a
    > delete button. All the corresponding records will be deleted.
    >
    > But I'm running into difficulty...
    >
    >
    > Right now the NAME property of each check box is the primary key of the
    > corresponding record. Hence if I know which checkboxes are checked, I
    > simply use DELETE using the NAME value.
    >
    > Generally speaking, how do I get the server side to see which check boxes
    > were checked?
    >
    > The check box names may not be sequential, if any records have been deleted
    > previously, and the first check box might be a number greater than 0.
    >
    > Is there an easy mechanism to do this? Some kind of built in cnotrol array
    > allowing me to loop over every check box that was on the form submitted?
    >
    > I could store the last and first checkbox number in a hidden input, then
    > loop starting/ending at those values, but that may loop over a lot of
    > controls that do not exist.
    >
    >
    > Thoughts?
    >
    >
    >
    > <Ade
    generate the list with something like this:

    $result = mysql_query("SELECT * FROM table", $fh);
    while ($row = mysql_fetch_array($result)) {
    echo "<input name="id[]" type="check value="$row[0]"><br>";
    }

    then when it gets passed to the serverside, $_POST['id'] will be an
    array containing the values of the checked boxes. Just walk through the
    array deleting them one by one.

    Off the top if my head without testing:

    $delete = $_POST['id'];
    foreach ($delete as $this) {
    mysql_query("delete from table where id=$this");
    }

    I hope this helps, and btw, it took me a while to understand how
    checkboxes were handled too.
    Milambar Guest

  4. #3

    Default Re: Handle Multiple Check Boxes?

    Milambar wrote:
    > Adrian Parker wrote:
    >
    >> I have a PHP generated page which displays X many records. Each
    >> record has
    >> a checkbox preceding it. The user checks several checkboxes, and hits a
    >> delete button. All the corresponding records will be deleted.
    >>
    >> But I'm running into difficulty...
    >>
    >>
    >> Right now the NAME property of each check box is the primary key of the
    >> corresponding record. Hence if I know which checkboxes are checked, I
    >> simply use DELETE using the NAME value.
    >>
    >> Generally speaking, how do I get the server side to see which check boxes
    >> were checked?
    >>
    >> The check box names may not be sequential, if any records have been
    >> deleted
    >> previously, and the first check box might be a number greater than 0.
    >>
    >> Is there an easy mechanism to do this? Some kind of built in cnotrol
    >> array
    >> allowing me to loop over every check box that was on the form submitted?
    >>
    >> I could store the last and first checkbox number in a hidden input, then
    >> loop starting/ending at those values, but that may loop over a lot of
    >> controls that do not exist.
    >>
    >>
    >> Thoughts?
    >>
    >>
    >>
    >> <Ade
    >
    > generate the list with something like this:
    >
    > $result = mysql_query("SELECT * FROM table", $fh);
    > while ($row = mysql_fetch_array($result)) {
    > echo "<input name="id[]" type="check value="$row[0]"><br>";
    > }
    >
    > then when it gets passed to the serverside, $_POST['id'] will be an
    > array containing the values of the checked boxes. Just walk through the
    > array deleting them one by one.
    >
    > Off the top if my head without testing:
    >
    > $delete = $_POST['id'];
    > foreach ($delete as $this) {
    > mysql_query("delete from table where id=$this");
    > }
    >
    > I hope this helps, and btw, it took me a while to understand how
    > checkboxes were handled too.
    Meh, dont forget to escape the quotes in the generation part:
    echo "<input name=\"id[]\" type=\"checkbox\" value=\"$row[0]\"><br>";

    Sorry. But it is 3am here at the moment.
    Milambar Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139