monkeytooth Posted June 26, 2008 Share Posted June 26, 2008 Ok think of gmail.. and how they list the mail in the inbox.. OK. So my thing isnt nearly as elaberate, however I do have a ever expanding list of users in my database. I have a generic script that I made that lists them, and lists them with options to preform the needed maintencer on there accounts. And well with the DB getting larger its becoming 1 a burden to repeat each task individually to those I need to preform the task on and 2 very tedious. So I want to revise my script by adding a "Checkbox" next to every name (which I can do). What I am looking for is how do I use the checkboxes, I know how to use them well enough when they are static within a form, but not dynamicly created. How would I work it if I selected out of 100+ people on a list, only 10 people. Say I selected users 10, 20, 30, 45, 73, 88, 91, 92, 97, 103 (for examples sake) How would I on submit of the form get it to recognize that I selected those? (we'll say for examples sake that the Checkbox Input name is "Chkbx_ID" and right after "ID" is added there ID number from the db to make each box unique in name (Which I can change if need be I just thought thats how it was done, but I can't wrap my mind around how to do this) Well hopeful I haven't lost you with all the babble.. Can anyone help? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 For the checkboxes, for it like this, where $user_id is the users unique identification number <input type="checkbox" name="Chkbx_ID[<?php echo $user_id ?>]" /> then on the page it posts to: <?php if(is_array($_POST['Chkbx_ID'])){ //Users have been selected foreach(array_keys($_POST['Chkbx_ID']) as $user_id){ //Do actions on $user_id here } } ?> Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 26, 2008 Author Share Posted June 26, 2008 Will go try that right now, thank you. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 26, 2008 Share Posted June 26, 2008 The best way to do this is to create the HTML for the checkboxes so that they are an array. You can then differentiate the selected IDs by one of two means: 1) Set the array index to the ID 2) Set the value attribute to the ID The goal is to have your HTML checkboxes look like this: <input type="checkbox" name="selected[1]" /> <input type="checkbox" name="selected[2]" /> <input type="checkbox" name="selected[3]" /> This will cause $_POST['selected'] to be an array where each index in the array is the ID of a database item that was checked. After you've modified your output to be like the above, add this at the top of your processing page and see if you can't figure out the rest: <?php echo '<pre style="text-align: left;">' . print_r( $_POST['selected'], true ) . '</pre>'; ?> (edit) rhodesa beat me to it, but since I'd already typed out my response I just let it through. 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.