mattyt81 Posted October 10, 2011 Share Posted October 10, 2011 Hi I have to multi select tables, the table on the left is field with the contents of an array, I then have it so the user can make there selections from the left box and move them into the right. They then hit submit and it gets stored inmysql table as an array. The problem I am having is keeping the selections in that right box after any sort of page refresh. Any ideas I have pasted the php and html code below, the add/remove function is controlled by javascript, I won't bother pasting that as i don't think it has anything to do with it. PHP ******** <?php / ------- PARSING PERSONAL TRAINER DETAILS VENUE --------- if ($_POST['parse_var'] == "fromPool"){ $venue = $_POST['venue']; if (is_array($_POST['venue'])) { $venue = explode("\n", $_POST['venue']); } else { $venue = $_POST['venue']; } // Update the database data now here for all fields posted in the form $sqlUpdate = mysql_query("UPDATE ptdata SET venue='$venue' WHERE id='$id' LIMIT 1"); if ($sqlUpdate){ $success_msg = '<img src="images/Form/round_success.png" width="20" height="20" alt="Success" />Your venue information has been updated successfully'; } else { $error_msg = '<img src="images/Form/round_error.png" width="20" height="20" alt="Failure" /> ERROR: Problems arose during the information exchange, please try again later</font>'; } } // ------- END PARSING PERSONAL TRAINER DETAILS VENUE --------- ?> <?php ////////// Venue Array PHP For Multi Selection Boxes //////////// $dbString = ''; // To be pulled from Database $toPool = explode(',', $dbString); $pool = Array('Your Home','My Home','Outside','Private Studio','Your Work','Gym'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $toPool = (count($_POST['venue']) > 0)? $_POST['venue'] : Array(); $newDbString = implode(',', $toPool); // Store in Database; } $fromPool = array_diff($pool, $toPool); ?> html *********** <form action="ptmemberaccount.php" method="post" enctype="multipart/form-data"onsubmit="multipleSelectOnSubmit()"> <table width="500" align="left"> <tr> <td width="500" height="300" align="center"> <select multiple="multiple" name="fromBox[]" id="fromBox"> <?php foreach($fromPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> <select multiple="multiple" name="venue[]" id="toBox"> <?php foreach($toPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> </td> </tr> <tr> <td align="center" height="35"><script type="text/javascript"> createMovableOptions("fromBox","toBox",400,200,'Training Venues','Selected Training Venues'); </script> <p>Use the buttons to Add/Remove selections</p></td></td> </tr> <tr> <td align="center" height="100"> <input type="submit" value="OK"> </tr> </table> </form> If you need anymore info let me know, also if anyone knows a better way of achieving this i am open to suggestions. Many Thanks MOD EDIT: code tags added Quote Link to comment https://forums.phpfreaks.com/topic/248832-php-multi-selection-lists/ Share on other sites More sharing options...
Pikachu2000 Posted October 10, 2011 Share Posted October 10, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/248832-php-multi-selection-lists/#findComment-1277874 Share on other sites More sharing options...
jcbones Posted October 10, 2011 Share Posted October 10, 2011 To keep the items after page re-fresh, you would need to create a SESSION, COOKIE, or fill with a database pull. Since you are adding them to the DB, I would suggest pulling them from the DB. Quote Link to comment https://forums.phpfreaks.com/topic/248832-php-multi-selection-lists/#findComment-1277878 Share on other sites More sharing options...
mattyt81 Posted October 12, 2011 Author Share Posted October 12, 2011 Hi I have tried that but it doesn't seem to work, it should but it doesn't Quote Link to comment https://forums.phpfreaks.com/topic/248832-php-multi-selection-lists/#findComment-1278505 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.