Hey gang, I've got a complex algorithm that I'm trying to work out. I'm trying to store and retrieve a set of switches in a decimal representation of a binary number. I have four checkboxes, call them A, B, C, and D. They can be represented by a (decimal) number from 0 to 15 in binary (0000 to 1111). I need to be able to store and retrieve this set of data.
I've got the script to store it, and I thought I had the script to retrieve the data, but I can't seem to get the checkboxes to actually be checked (or not) depending on the value in the database. I don't like dealing with the data this way, but the program I'm interacting with requires it. The script below is used to handle a number of data elements on the page. $pagevars is an array of the variables on the page, and the table they are located in. set_val(a,b) puts the values in array a into the variables listed in array b. form_element(a,b) is a function that returns a form element of type a (CB, TB) with the variable a. So form_element("CB","var") returns the following: <INPUT TYPE="CHECKBOX" NAME="var" /> If the value is 1 or on, CHECKED will be added. Here's the script: --- START CORE.PHP --- <?php include("../functions.inc"); include("menu.html"); $pagevars=array("statistics"=>array("StatFlags","StatFiles","StatMail","STF_Hours","STM_Hours")); if (isset($_POST['submit'])) { $stat=$_POST['stat']; for ($i=0;$i<4;$i++) { $t[$i]=isset($stat[$i])?"1":"0"; } $stat=implode("",$t); $StatFlags=bindec($stat); $_POST['StatFlags']=$StatFlags; unset($_POST['stat']); if (!set_val($_POST,$pagevars)) { echo "data not written to database. Contact system administrator"; } } $page_var_vals=get_vars($pagevars); if (is_array($page_var_vals)) { extract($page_var_vals); } echo "StatFlags:$StatFlags<BR>"; $stat=preg_split('//', str_pad(decbin($StatFlags), 4, "0", STR_PAD_LEFT), -1, PREG_SPLIT_NO_EMPTY); for ($i=0;$i<4;$i++) { $stat[$i]=($stat[$i]==1)?"on":""; } debug($stat); ?> <H1>Statistics</H1> <FORM METHOD="POST" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><?php form_element("CB","stat[0]"); ?>Save statistics to a file periodically Every <?php form_element("TB","STF_Hours"); ?>hours</p> <p>Save in: <?php form_element("TB","StatFiles"); ?></p> <p><?php form_element("CB","stat[1]"); ?>Email statistics periodically Every <?php form_element("TB","STM_Hours"); ?>hours</p> <p>Send to: <?php form_element("TB","StatMail"); ?></p> <p><?php form_element("CB","stat[2]"); ?>Automatically open the statistics window at startup</p> <p><?php form_element("CB","stat[3]"); ?>Collect statistics about mail sent by local users</p> <p>System Messages</p> <p>System reporting level: <SELECT NAME=""> <option value="0"> 0 - No messages </option> <option value="1"> 1 - Urgent messages </option> <option value="2"> 2 - Significant messages </option> <option value="3"> 3 - Normal messages </option> <option value="4"> 4 - Informational messages </option> <option value="5"> 5 - Debugging messages </option> </SELECT></p> <p>Number of messages to store: <?php form_element("TB",""); ?></p> <p><?php form_element("CB",""); ?> Automatically open the system messages window on startup</p> <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Save" /> <INPUT TYPE="Reset" VALUE="Cancel" /> </form> </body> </html> --- END CORE.PHP --- ===== Mark Weinstock [EMAIL PROTECTED] *************************************** You can't demand something as a "right" unless you are willing to fight to death to defend everyone else's right to the same thing. *************************************** __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php