Mutley Posted March 9, 2007 Share Posted March 9, 2007 I have a list and what I would like to do with this list is have a tick-box next to each one, so someone can select multiple things out of the list. Then, once they click "submit", it displays just the things they selected. The list in the data is displayed from a database by repeating the rows, so if there are 3 rows, it displays it in a table repeating the <tr><td><?=$thing?></td></tr> until it ends. I know how to do forms, just not how to post only the selected data, to display it on a different page. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/ Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 well show the form you got then? Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-203808 Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 Only selected checkbox values are sent so you can do this <?php if (isset($_GET['thing'])) { echo "You selected "; foreach ($_GET['thing'] as $item) { echo " <br />$item"; } } ?> <form> Thing 1 <input type='checkbox' name='thing[]' value='Thing1'><br> Thing 2 <input type='checkbox' name='thing[]' value='Thing2'><br> Thing 3 <input type='checkbox' name='thing[]' value='Thing3'><br> <input type='submit' name='action' value='Submit'> </form> Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-203935 Share on other sites More sharing options...
Mutley Posted March 10, 2007 Author Share Posted March 10, 2007 My form is like this: {All the items variables to display} <input type="checkbox" name="order" value="<?=$id?>" /> Then when they click submit it goes to newdisplay.php In which that file grabs the $id of all the items chosen. So, I know how I display the items information using the $id, just don't know how "newdisplay.php" knows all the $id's ? How do I carry them across? Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204185 Share on other sites More sharing options...
Barand Posted March 10, 2007 Share Posted March 10, 2007 <checkbox name="order[<?=$id?>]" value="1" /> then <?php foreach ($_POST['order'] as $id => $x) { echo "You selected item ID: $id<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204186 Share on other sites More sharing options...
Mutley Posted March 10, 2007 Author Share Posted March 10, 2007 Worked a treat. How do I use that to pull more fields out of the same IDs row? Do I do a SQL query or can I take it off the page POST using the checkbox like it did with the ID? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204265 Share on other sites More sharing options...
legohead6 Posted March 10, 2007 Share Posted March 10, 2007 you can use that varible to fetch from a database or whatever you want.. Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204296 Share on other sites More sharing options...
Barand Posted March 10, 2007 Share Posted March 10, 2007 If you want to pass other data that is associated with the same record as the order id, such as order_date, then name that order_date[$id] When processing <?php foreach ($_POST['order'] as $id = $x) { $order_date = $_POST['order_date'][$id]; // gets associated date field // process select orders } ?> An other way is to switch it round slightly and name the checkbox as name="orders[]" and value="$id" (similar to what you had originally except name end with [] ). Now you can easily pull the orders with selected ids with <?php $idlist = join (',' , $_POST['orders'] ); $sql = "SELECT * FROM orders WHERE id IN ($idlist)"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204333 Share on other sites More sharing options...
Mutley Posted March 11, 2007 Author Share Posted March 11, 2007 Thanks, got it working, I want to take it one step further now. If I go to a different page, where it has another list and tick some more how can I make it remember the ones I ticked on the previous page? So when I compile a new page with only the ones ticked, it shows from both pages and not just one? Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204875 Share on other sites More sharing options...
interpim Posted March 11, 2007 Share Posted March 11, 2007 session or cookie variables... just load them on the pages you want to know the info... Quote Link to comment https://forums.phpfreaks.com/topic/42031-multiple-tick-box-select/#findComment-204876 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.