Page 1 of 1

Troubles with Check Boxes -- Help needed :)

Posted: Tue Dec 02, 2003 12:20 pm
by gjb79
I am having trouble creating series of check boxes from an array that is built from an sql database. I need to take these check boxes and compair them to a second array to determine of they start off checked or unchecked.

This printed out one check box (insted of one checkbox for each item in the array). it also gave me a warning:
Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/public_html/test.php on line 104

Code: Select all

<?php
  while ( $row = mysql_fetch_array($filelist) ) {
  $test_value = $row_filelist['ID'];
  echo  "<input name='selectedfile[]' type='checkbox' value='" . $test_value . "'";
	  while ( $row2 = mysql_fetch_array($FiletoPagelist) ) {
	   if ( $row2_FiletoPagelist['file'] == $test_value ) {
	   echo " checked>";
	   }
	   else {
	   echo ">";
	   }
	  }
  
  mysql_data_seek ($FiletoPagelist['file'],0);

  }
  ?>
This produced 1 check box with a value of 5. There should be a second check box with a value of 6. Also both check boxes should load as being checked.

Posted: Tue Dec 02, 2003 1:11 pm
by xisle
I usually do something like this...

Code: Select all

while(list($id)=mysql_fetch_array($result1))&#123;
    $checkarray&#1111;]=$id;
&#125;

while(list($id,$name)=mysql_fetch_array($result2))&#123;
      
  echo "<input name='selectedfile&#1111;]' type='checkbox' value='&#123;$id&#125;'";
  
  if(in_array("&#123;$id&#125;",$checkarray))&#123;
      echo " checked"; 
   &#125; 
   echo ">&#123;$name&#125;"; 
 
&#125;