hwcasey12 Posted April 29, 2009 Share Posted April 29, 2009 I am building a form that allows the user to select "days" from a checkbox list. Form (newclient.inc.php): <td><h3>Training Schedule:</h3></td> <td><input type="checkbox" name="day[]" value="m">Monday <input type="checkbox" name="day[]" value="t">Tuesday <input type="checkbox" name="day[]" value="w">Wednesday <input type="checkbox" name="day[]" value="r">Thursday <input type="checkbox" name="day[]" value="f">Friday <input type="checkbox" name="day[]" value="s">Saturday </td> Process (addclient.inc.php): $day = serialize($_POST['day']); If a user selects Monday, Wednesday, & Friday it is storing in the mysql db as: a:3:{i:0;s:1:"m";i:1;s:1:"w";i:2;s:1:"f";} QUESTION: 1) I am not sure if that is the proper way to store the data. 2) I want to be able to extract that information so that I can view the details of a user's training schedule. For example, "MWF". Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/156173-solved-form-w-checkboxes-inserting-and-viewing-help/ Share on other sites More sharing options...
mikesta707 Posted April 29, 2009 Share Posted April 29, 2009 use the unserialize function to turn it back into an array http://us.php.net/unserialize Quote Link to comment https://forums.phpfreaks.com/topic/156173-solved-form-w-checkboxes-inserting-and-viewing-help/#findComment-822162 Share on other sites More sharing options...
hwcasey12 Posted April 29, 2009 Author Share Posted April 29, 2009 Okay Thanks! I changed my "viewc.inc.php" file to: <?php include ("include/dbconnect.php"); include ("include/format.inc.php"); $id = $_GET['id']; $query = "SELECT id, firstname, lastname, address, city, state, zip, day, time FROM client WHERE id = $id"; $result = mysql_query($query) or die('Could not find client'); $row = mysql_fetch_array($result, MYSQL_ASSOC) or die('No records retrieved'); $id = $row['id']; $firstname = $row['firstname']; $lastname = $row['lastname']; $address = $row['address']; $city = $row['city']; $state = $row['state']; $zip = $row['zip']; $day = unserialize($row['day']); $time = $row['time']; echo "<h2>$firstname $lastname <a href=\"index.php?content=editc&id=$id\" target=\"_blank\"><img border=0 src=icons/pencil.png width=16 height=16 title='".'Edit'."' alt='".'Edit'."'/></a> <a href=\"print.php?id=$id\" target=\"_blank\"><img border=0 src=icons/printer.png width=16 height=16 title='".'Printer Friendly'."' alt='".'Printer Friendly'."'/></a></h2>"; echo "<h4>$address</h4>"; echo "<h4>$city, $state $zip</h4>"; echo "<h4>Schedule:$day @ $time"; ?> On the output I get the word "Array". What is the next step to viewing the data? Quote Link to comment https://forums.phpfreaks.com/topic/156173-solved-form-w-checkboxes-inserting-and-viewing-help/#findComment-822165 Share on other sites More sharing options...
mikesta707 Posted April 29, 2009 Share Posted April 29, 2009 well what you would have to do is do a foreach to output it, as you cant simply echo an array (unless you wanted to use the print_r function, but that would echo the structure of the array, and not simply the values that are in it. some something like $string = ""; foreach($day as $day){ $string .= $day; } echo "<h4>Schedule:$string @ $time"; that would put all the entries in the array into a the variable string. so if the day array had the values M, W, and Th, the string variable would become "MWTh". Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/156173-solved-form-w-checkboxes-inserting-and-viewing-help/#findComment-822183 Share on other sites More sharing options...
hwcasey12 Posted April 29, 2009 Author Share Posted April 29, 2009 Wow sure does! Got it! Big Thanks for teaching me to fish! Quote Link to comment https://forums.phpfreaks.com/topic/156173-solved-form-w-checkboxes-inserting-and-viewing-help/#findComment-822187 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.