What is the best way (if there is such a thing) to pass selected checkbox variables in a URL? These come from a "do while"

<table>
<?php do { ?>
<tr>
<td><strong>
<input type="checkbox" name="col[]" value="<?php echo $row_Recordset1['LID']?>">
</strong></td>
<td><strong><?php echo $row_Recordset1['county']?>, <?php echo $row_Recordset1['state']?></strong></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

A connecting page will take the values (3 maximum) and process a 3-part form, which also have "do whiles".

    What do you mean by passing them in a URL? If your form uses the GET method, then everything will be passed in the url.

    Also, and I could be missing something, why is the name of your checkbox a php array name, even though it's not inside of the php delimiters?

      why is the name of your checkbox a php array name,

      Sorry, this was copied directly from a form that inserts into a table.

      But still,when I use FORM ACTION with the page address, how can I pass the checkbox variables;

      2ndpage.com/?County=1stvalue, 2ndvalue,3rdvalue

      Do they each have to have their own name? How are they best called back on the connecting page so they can be outputted by 3 "do while" loop(s) (with checkboxes, but this time the 3 sets of values are inserted into table)

        Also, and I could be missing something, why is the name of your checkbox a php array name, even though it's not inside of the php delimiters?

        Naming a checkbox as an array will allow PHP to then see all the values that were checked. Otherwise, through POST, PHP will only see the last value checked. That way you can reference them like $_POST['checkbox'][0...n]

        About putting them through GET - Just give it a try! Set the form to GET, make the checkbox, make some selections, and see how it's passed and how PHP responds to it. If it doesn't work out, you might want to run a little JavaScript before the form is submitted, concatenating all checkbox variables with commas, and then changing the form's action to the new page, with the concatenated string in the URL. Then PHP will need to un-concatenate (or explode()) that particular variable.

        Something like:

        
        <script type='text/javascript'>
        
        function doYourStuff()
        {
             var len = document.form.check.length;
             var str = "";
             for (var i = 0; i < len; i++)
             {
                  str .= document.form.check[0].value + ",";
             }
        
         document.form.action = "page2.php?checkbox=" + str;
         document.form.submit();
        }
        
        </script>
        
        <form action='page2.php' method='get' name='form' onsubmit='return doYourStuff()'>
        <input type='checkbox' name='check' value=1>1<br />
        <input type='checkbox' name='check' value=2>2<br />
        <input type='checkbox' name='check' value=3>3<br />
        <input type='checkbox' name='check' value=4>4<br />
        <input type='checkbox' name='check' value=5>5<br />
        </form>
        
        

        Warning: you will have to clean up that code before it works. I didn't even test it; I just wrote it right here quickly. I can pretty much guarantee you it will not work as is, but that is the basic skeleton you'll need. It is possible - just keep working at it.

          $_POST['checkbox'][0...n]

          Do you reckon this will maintain the order in which they were checked (so each is not duplicated)

          Would I need to have in there SEL ORDER?

            Don't know if they will be in the same order, but then again, that's just if (and only if) GET sends the checkbox variable in that fashion so PHP can interpret it. If not, use the JS way.

            Sorry, don't know what SEL ORDER is. Enlighten me!

              Forgive me, I beleive I was referring to increment to track the order.
              Or, $i+1

                Allright...as long as I helped in some way, I'm glad 🙂

                  <input type="checkbox" name="col[]" value="<?php echo $row_Recordset1['LID']?>">?

                  Since you are using array checkbox in your form the best way to retrieve the data after you submit it

                  <? $checkbox=$POST['col']; // since checkbox is in your array you can use this one the $POSt['col'] read number of array
                  $howmany=count($checkbox); // now let us count how many checkbox are checked
                  for ($x=0;$x<$howmany;$x++) // now let us loop
                  {
                  echo $howmany[$x]; // now let us display checkbox that checked
                  }

                    6 days later

                    I'm having to process with get (POST won't pass variables):

                    <form action="stateexp2.php" method="get" name="form1">

                    Each of the checkboxes are coming up dynamically, for example (Alabama):

                    <input type="checkbox" name="states[]" value="AL">

                    <input type="submit" name="Submit" value="submit">


                    On stateexp2.exp the URLS is coming up as (West Virginia, Wyoming):

                    /stateexp2.php?states%5B%5D=WV&states%5B%5D=WY&Submit=submit

                    ...............

                    How can I retrive these (considering table interference of %5B%5D) ?

                      I'm assuming that %5B and %5D are [ and ] respectively. It looks like you can still access them like you would normally through post - $GET['states'][0], $GET['states'][1], etc.

                        LoganK

                        Can't get that to go. About the only thing I've been able to retrieve with is:

                        <?php echo $GET['states'];?>

                        gives "array"

                        <?php $checkbox= $HTTP_GET_VARS['?states'][0];

                        -gives " WY" the first col value, but the second in the URL
                        - but it won't seem to take a second or third value.

                        (that's okay, I'll ORDER BY the queries)

                        That first line is blanking the page out:
                        $checkbox= $GET['states'][0], GET['states'][1];

                        also, tried "$HTTP_GET_VARS" -- nothing

                        Is there a way to eliminate passing the "%5B%5D" in the URL at the form level?:

                        <form action="stateexp2.php" method="get" name="form1">

                          The %5B and %5D, if you read my earlier post, are [ and ], and they are needed in order for PHP to read it as an array. Try print_r($_GET); and post the results here.

                            print_r($_GET); // gives:

                            Array ( [states] => Array ( [0] => AZ [1] => NC [2] => ND [3] => WY ) [Submit] => submit )

                            .......................................................
                            My Main Concern is that I can have SELECT queries that exclude the %5B%5D and are able to call the states (as you can see I'm matching by StateCode) that will be on this same page, ex:

                            $colname_RecordsetSTATELY = "0";
                            if (isset($HTTP_GET_VARS['states'])) {
                            $colname_RecordsetSTATELY = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['states'] : addslashes($HTTP_GET_VARS['states']);
                            }
                            mysql_select_db($database_anything, $anything);
                            $query_RecordsetSTATELY= sprintf("SELECT DISTINCT State, StateCode FROM MYTABLE WHERE StateCode='%s' ", $colname_RecordsetSTATELY);
                            $RecordsetSTATELY = mysql_query($query_RecordsetSTATELY, $anything) or die(mysql_error());
                            $row_RecordsetSTATELY = mysql_fetch_assoc($RecordsetSTATELY);
                            $totalRows_RecordsetSTATELY = mysql_num_rows($RecordsetSTATELY);

                              The %5B and %5D won't be in the field data, they're part of the form fields' names.

                              addslashes($HTTP_GET_VARS['states']

                              This won't work (and nor will using $_GET instead of $HTTP_GET_VARS), because $HTTP_GET_VARS['states'] is an array (as you found when you tried to echo it).

                              Since you're wanting to match records where StateCode is any one of those submitted, you can't just use "Where StateCode='whatever'". Try "where StateCode IN ($colname_RecordsetSTATELY)".

                              Getting $colname_RecordsetSTATELY:

                              $states = get_magic_quotes_gpc() ? $_GET['states'] : array_map('addslashes', $_GET['states']);
                              $colname_Recordset = "'".join("','",$states),"'";
                              

                                I'm confused by Weedpacket's post...but from your print_r, it looks like you can reference the values individually by using $GET['states'][0], $GET['states'][1], etc.

                                  But I can't reference it by:
                                  <?php $checkbox= $GET['states'][0], $GET['states'][1];

                                  The page goes blank.

                                    Because you're not echoing anything, plus you're using a comma. Try

                                    echo $_GET['states'][0];
                                    

                                      LoganK:

                                      <?php $checkbox= echo $_GET['states'][0];

                                      makes the page go blank.

                                        WeedPacket:

                                        If I understand you, here is what I have (but no work yet)

                                        $colname_Stately = "0";
                                        if (isset($HTTP_GET_VARS['states'])) {
                                         $states = get_magic_quotes_gpc() ? $_GET['states'] : array_map('addslashes', $_GET['states']); 
                                        $colname_Stately = "'".join("','",$states),"'";  
                                        } mysql_select_db($database_removed, $removed); $query_Stately = sprintf("SELECT DISTINCT State, StateCode, StateFIPS FROM commercial9 WHERE (StateCode!= 'AS') AND (StateCode!= 'AA') AND (StateCode!= 'AE') AND (StateCode!= 'AP') AND (StateCode!= 'FM') AND (StateCode!= 'MP') AND (StateCode!= 'PW') AND %s = StateCode", $colname_Stately); $Stately = mysql_query($query_Stately, $removed) or die(mysql_error()); $row_Stately = mysql_fetch_assoc($Stately); $totalRows_Stately = mysql_num_rows($Stately);

                                        This too makes the page go blank.