title: Checking tick boxes from data from database
body: <p><strong><em>Sorry I should of explained this better. I tried to make it simple. What this form does is bring up a persons details and then the user can select, using the tick boxes, whether that person can have certain things (like rest breaks). So when the form is loaded the tick boxes are already ticked for the certain things... If that made sense. If a person was already entitled to rest breaks. and I load their details up on the form. The box for rest breaks should already be ticked.</em></strong></p>
  
  <p>The student id is for the form to display the person that has been selected on the form. Also the status is corresponding to the request. it is either awaiting approval, approved or rejected.</p>
  
  <pre><code>                $selected_arrangement_query = "
              SELECT tbl_arrangement_id, arrangement, ta.status
              FROM tbl_arrangement AS ta
              WHERE 
              tbl_student_id = $selected
  </code></pre>
  
  <p>I'll keep this question short. What is going on is that I have a form with tick boxes on. Once the user clicks the text box it will post the data to the database and then show on the form as that option has been selected. But the the tick from the text box disappears. I want to make it so that once the data has been submitted the tick will remain there. There are about 40 boxes so I am expecting the coding to be long for all the different permutations but if someone can help me get started I can replicate it further.</p>
  
  <p>Here is the start of it. The first few hidden values are just there to get the same user so it.</p>
  
  <pre><code>        &lt;table&gt;
          &lt;form name='counter' id='counter' method="get"  &gt;
              &lt;tr&gt;&lt;th colspan="8"&gt;Counter arrangements&lt;/th&gt;&lt;/tr&gt;  
              &lt;input type="hidden" name="selected" value="&lt;?php echo $selected; ?&gt;" /&gt;
              &lt;input type="hidden" name="edited" value="1" /&gt; 
              &lt;input type="hidden" name="evidenceCount" value="&lt;?php echo $selected_evidence_Total; ?&gt;" /&gt;
              &lt;input type="hidden" name="arrangementCount" value="&lt;?php echo $selected_arrangement_Total; ?&gt;" /&gt;  
  
              &lt;td valign="top"  &gt;
                &lt;input type="checkbox" Name='arrangements[]'  value='Rest Breaks' OnChange='this.form.submit();'&gt;Rest Breaks&lt;/option&gt;
              &lt;/td&gt;           
              &lt;td valign="top"  &gt;
                &lt;input type="checkbox" Name='arrangements[]' value='Small Classroom Environment' OnChange='this.form.submit();'&gt;Small Classroom Environment&lt;/option&gt;
              &lt;/td&gt;
              &lt;td valign="top"  &gt;
                &lt;input type="checkbox" Name='arrangements[]' value='Coloured Overlay' OnChange='this.form.submit();'&gt;Coloured Overlay&lt;/option&gt;
              &lt;/td&gt;
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>Here is the code for the drop down boxes for approved rejected etc.</p>
  
  <pre><code> &lt;?php
      //declare counter
      $rowcount = 0;
      while ($row = $selected_arrangement_result-&gt;fetch_assoc()) {
          printf("&lt;tr&gt;");
          printf("&lt;td&gt;&lt;input type='hidden' name='arrangementRowID%s' value='%s' /&gt;",$rowcount,$row['tbl_arrangement_id']);
          printf("%s&lt;/td&gt;",$row['arrangement']);
          if($row['status']=='Awaiting Approval'){
          ?&gt;
  
  
          &lt;td class="right"&gt;
          &lt;select name='astatus&lt;?php echo $rowcount; ?&gt;' onchange='submitForm()'&gt;
              &lt;option value='Awaiting Approval' selected="selected"&gt;Awaiting Approval&lt;/option&gt;
              &lt;option value='Approved'&gt;Approved&lt;/option&gt;
              &lt;option value='Rejected'&gt;Rejected&lt;/option&gt;
              &lt;option value='Rejected-No Evidence'&gt;Rejected-No Evidence&lt;/option&gt;
              &lt;option value='Approved on Appeal'&gt;Approved on Appeal&lt;/option&gt;
              &lt;option value='Approved Alternative' &gt;Approved Alternative&lt;/option&gt;
          &lt;/select&gt;
          &lt;/td&gt;
          &lt;?php
          }elseif($row['status']=='Approved'){
          ?&gt;
          &lt;td class="right"&gt;
          &lt;select name='astatus&lt;?php echo $rowcount; ?&gt;' onchange='submitForm()'&gt;
              &lt;option value='Awaiting Approval'&gt;Awaiting Approval&lt;/option&gt;
              &lt;option value='Approved' selected="selected"&gt;Approved&lt;/option&gt;
              &lt;option value='Rejected'&gt;Rejected&lt;/option&gt;
              &lt;option value='Rejected-No Evidence'&gt;Rejected-No Evidence&lt;/option&gt;
              &lt;option value='Approved on Appeal'&gt;Approved on Appeal&lt;/option&gt;
              &lt;option value='Approved Alternative' &gt;Approved Alternative&lt;/option&gt;
          &lt;/select&gt;
          &lt;/td&gt;
  </code></pre>
  
  <p>After more research I have found more code. I have amended it to fit my needs, will something like this work?
  I know i will need to include all of the check boxes once I am done. I also will need an if statement for each but I want to get the first one working first.</p>
  
  <pre><code>         $arrangement = mysql_query("SELECT tbl_arrangement_id, arrangement FROM tbl_arrangement WHERE Id=$selected");
            $row = mysql_fetch_row($arrangement);
            $selected = explode(',', $row[$arrangement]);
            $j=0;
            for($i=0; $i&lt;count($arrangement); $i++){
               if($j&lt;count($selected) &amp;&amp; $selected[$j] == $arrangements[$i]){
                  echo $arrangements[$i]." &lt;input type='checkbox' name='arrangements[]' value='". $arrangement[$i] ."' checked&gt; ";
                  $j++;
               }
              else echo $arrangements[$i]." &lt;input type='checkbox' name='arrangements[]' value='". $arrangement[$i] ."'&gt; ";
            }
  </code></pre>