Hi all got a problem with setting the value of a checkbox depending on the result of a SELECT statement, when creating the checkbox with Dreamweaver I get this code (i added some php)

<td><font face="Tahoma"> Track:

<?php

print "<input type=checkbox name=track2 value=track2>";
?>

</font></td>

OK, now i have an array $row[] that has a boolean value in it, how do i get the checkbox to appear checked if the boolean value is true?

Also how do i send the new value when the form is submitted.

Any help would be wicked!!

Cheers, N.😉

    for ($i=0;$i<count($row);$i++) {
      if (!$row[$i]) {
        print "<input type=\"checkbox\" name=\"track2\" value=\"track2\">";
      } else {
        print "<input type=\"checkbox\" name=\"track2\" value=\"track2\" checked>";
      }
    }
    

      Worked a treat Thorpe - many thanks!! While i'm here i'm also having the same problems with a drop down menu, anyone know how to set and send those values??

        its exactly the same.... what do you want to set? and im not quite with you in regardds to submission. forms take care of submission themselves. well, aslong as you provide a submit button. :-P

        just post your code...

          <td><div align="right"><font face="Tahoma">User Level:</font></div></td>
          <td><select name="select">
          <option>Admin</option>
          <option>User</option>
          </select></td>

          Thats the HTML but i just want to know how to set the initial value depending the result of a SELECT statement. I am using a submit button, do i just $_REQUEST['select'] on the next page??

          Cheers, N. 🆒

            how to set the initial value depending the result of a SELECT statement

            still not 100% on what your trying to do here. do you mean you want to select an option in the list depending on a 'SELECT' database query?

              Yep exactly, what i'm doing is editing 'people' in a database - these people have a user level which can be set to 'user' or 'admin' So when editing these 'people' the initial value should be the same as whats in the database. Then if the user changs the value this will be sent to another page for processing in an 'UPDATE' statement.

              Hope thats a bit clearer

              Cheers, N.🆒

                you sure you really want users to be able to 'make' themselves admin's? shouldn't admins be the only users able to add admins?

                  Yeah if the user status is set to 'user' they wont be able to get this far they will be cut off much earlier in the system. Any ideas on the drop down menu?

                  N. :bemused:

                    without seeing your query...

                    ?>
                    <td><div align="right"><font face="Tahoma">User Level:</font></div></td>
                    <td><select name="select">
                    <?php
                    
                      if ($result['status'] == 'admin') {
                        echo '<option selected>Admin</option>';
                        echo '<option>User</option>';
                      } elseif ($result['status'] == 'user') {
                        echo '<option>Admin</option>';
                        echo '<option selected>User</option>';
                      }
                    ?>
                    </select></td>
                    
                      Write a Reply...