Whats wrong with my code?

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:

Whats wrong with my code?

Post 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!!! :)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

i take it you have actually connected to the database elsewhere!?
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

he actually told us where the error was :)
Line 104 is the line containing the mysql_data_seek()
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

ah yes, sorry, i had mysql_fetch_array in my head cos i was just typing that in my own project :)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

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