Troubles with Check Boxes -- Help needed :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Troubles with Check Boxes -- Help needed :)

Post 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.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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;
Post Reply