techiefreak05 Posted June 12, 2007 Share Posted June 12, 2007 I was wondering how to run a query for every check box checked, Ive looked around the net and nothing I've come accross is too usefull. Quote Link to comment https://forums.phpfreaks.com/topic/55301-checkboxes/ Share on other sites More sharing options...
akitchin Posted June 12, 2007 Share Posted June 12, 2007 the net is always useful where most programming is concerned, you just need to know what you're looking for. you need to know two things; first, how checkboxes work, and second, how to process arrays. checkboxes will only send values if they are checked. if they are unchecked, no variable will even be initialized in the $_POST array. second, you can name any HTML input as an array, resulting in its value being placed into the relevant sub-array item created in $_POST. that being said, you can do something like this: ID 1 <input type="checkbox" name="ids_checked[]" value="1" /> ID 2 <input type="checkbox" name="ids_checked[]" value="2" /> ID 3 <input type="checkbox" name="ids_checked[]" value="3" /> and in the PHP processing the form input, process through the $_POST['ids_checked'] array: foreach ($_POST['ids_checked'] AS $this_id) { $query = SOME QUERY USING $this_id; } i'm sure you can expand from there. if you need to relate that checkbox to a certain set of information (like a row, for example), then use its ID as the index in the other information, and name that as an array: <input type="text" name="title[this_rows_id]" value="some title" /> give it a whirl. Quote Link to comment https://forums.phpfreaks.com/topic/55301-checkboxes/#findComment-273365 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.