Page 1 of 1

Whats wrong with my code?

Posted: Thu Dec 04, 2003 9:59 pm
by gjb79
Anybody see what is wrong with this script?

Code: Select all

<?php
$reset_data_seek = $row_FiletoPagelist['file'];

  while ( $row = mysql_fetch_array($filelist) ) {
  $test_value = $row['ID'];
  echo  "<input name='selectedfile[]' type='checkbox' value='" . $test_value . "'";
	  while ( $row2 = mysql_fetch_array($FiletoPagelist) ) {
	   if ( $row2['file'] == $test_value ) {
	     echo " checked";
	   }
	   echo ">";
	   
	  }
  
  mysql_data_seek ($row2,$reset_data_seek);
  }
?>
This is what it prints on screen:
[form check box here, unchecked] checked>
Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/gregoryj/public_html/manage/manage/test.php on line 104

[form check box, unchecked] Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/gregoryj/public_html/manage/manage/test.php on line 104
Line 104 is the line containing the mysql_data_seek()

I'm just trying to get it to print out a list of check boxes, and check the ones that should be checked, by compairing two values from two different arrays.

Thanks for any help you can offer!!! :)

Posted: Fri Dec 05, 2003 3:08 am
by JayBird
i take it you have actually connected to the database elsewhere!?

Posted: Fri Dec 05, 2003 8:02 am
by gjb79
Yes, I am only giving the part of the code I believe has an error, I have my connection and select statements elsewhere.

I've tested them to make sure they produce the correct values, and they do.

Posted: Fri Dec 05, 2003 8:30 am
by JayBird
im not sure whick line is 104 but it is either

Code: Select all

while ( $row = mysql_fetch_array($filelist) ) {
or...

Code: Select all

while ( $row2 = mysql_fetch_array($FiletoPagelist) ) {
You need to show us how your are setting $FiletoPagelist or $filelist (whichever is line 104) becuase as the error says, one of these isn't a valid MySQL result resource .

Mark

Posted: Fri Dec 05, 2003 8:33 am
by Draco_03
he actually told us where the error was :)
Line 104 is the line containing the mysql_data_seek()

Posted: Fri Dec 05, 2003 8:43 am
by JayBird
ah yes, sorry, i had mysql_fetch_array in my head cos i was just typing that in my own project :)

Posted: Fri Dec 05, 2003 8:53 am
by JayBird
okay, you need to do this again outside the while loop

Code: Select all

$row2 = mysql_fetch_array($FiletoPagelist)
Because the result resource is only valid for the duration of the while loop.

Mark

Posted: Fri Dec 05, 2003 9:25 am
by gjb79
Excellent. That seems to have done something good.

However there is still an odd problem.

My Code:

Code: Select all

<?php
$row = mysql_fetch_array($filelist);
$row2 = mysql_fetch_array($FiletoPagelist);

  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 ( $row_FiletoPagelist['file'] == $test_value ) {
	     echo " checked";
	   }
	  }
	  echo ">";
       
  mysql_data_seek ($FiletoPagelist,0);
  }  ?>
Here is html source that shows what is displayed:

Code: Select all

&lt;input name='selectedfile&#1111;]' type='checkbox' value='5' checked&gt;

There should be 3 boxes with the values 5, 6, and 7, accordingly.
It looks like the outer loop is not looping at all.

The Arrays:
filelist - multidimensional array from an SQL database. The table column needed for this operation is ID ($row_filelist['ID'])
FiletoPagelist - Same as above, but with a different table. The table column is: files ($row_FiletoPagelist['files'])

I have tested the arrays individually from this script, they display the correct content. filelist shows (5,6,7) as does FiletoPagelist. Eventually FiletoPagelist might contain gaps (5,7). Durring this instance, there should be 3 check boxes (values 5,6,7) with 5 and 7 checked, and 6 left unchecked.


Thanks for all your help so far!!!!!!!!! :D