gamblor01 Posted July 24, 2009 Share Posted July 24, 2009 I have a page that will be generating unpredictable numbers of checkboxes (well unpredictable until the time the HTML is generated). It's a data mining application and depending on the selection made by the user, they will presented with a table that may have 10 rows, 42, or 100. My vision is to have a checkbox on each row, and allow the user to select any of the rows they want to throw out of the training set for my classifier. Thus, I need to be able to submit the form to a php page and determine which checkboxes were selected because those are the data values that I need to throw out. I know that if I had a form with a set number of fields this would be really easy. But because this can have any number of fields, I'm not sure how to tell which boxes are checked and which ones are not. Is this possible? Thoughts? Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted July 24, 2009 Share Posted July 24, 2009 Anything is possible if its logically correct. But how is this logical - you randomly give them some number of checkboxes and they select things to dump out. Quote Link to comment Share on other sites More sharing options...
gamblor01 Posted July 24, 2009 Author Share Posted July 24, 2009 Well the data isn't random, but the data is being pulled by a SQL query that pulls from one of many possible tables. Each table has a different number of rows in it, and it depends on which table the user selects. If they select TableA then I need to print 30 rows on a page. If they select table B then it's 7 rows, and so on. So the generic PHP code generating this page is just taking the rows returned and going through a loop to generate the HTML table. The idea is that the user would then be allowed to mark some of the rows as "questionable" and I need to know which rows those are. If I can't do this with checkboxes I suppose I could do this with a text both where they simply enter the row numbers that they think are questionable. Then I just pass that string when the form is submitted and I break it into separate tokens using comma/space/semicolon/colon/whatever as a delimiter. I might just code this up to use a text box where you enter the rows in a list for now (just to get it working) but ultimately I would really like to get it working with checkboxes. So far I don't really know how to do this without a gigantic if statement that has the same amount of conditions as the number of rows in the largest table. That sounds like a bad design. I'm just trying to figure out if there is something better. Quote Link to comment Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 <input type="checkbox" value="box1" name="checks[]" />box 1 <input type="checkbox" value="box2" name="checks[]" />box 2 <input type="checkbox" value="box3" name="checks[]" />box 3 This will put all the checked boxes (and only the checked boxes) into an array. So if you were to check box 1 and box 3, and then used this code: <?php print_r($_POST['checks']); ?> The output would be: Array ( [0] => box1 [1] => box3 ) Quote Link to comment Share on other sites More sharing options...
gamblor01 Posted July 25, 2009 Author Share Posted July 25, 2009 <input type="checkbox" value="box1" name="checks[]" />box 1 <input type="checkbox" value="box2" name="checks[]" />box 2 <input type="checkbox" value="box3" name="checks[]" />box 3 This will put all the checked boxes (and only the checked boxes) into an array. So if you were to check box 1 and box 3, and then used this code: <?php print_r($_POST['checks']); ?> The output would be: Array ( [0] => box1 [1] => box3 ) Now THAT is the slick solution that I was looking for! It works beautifully...thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.