Page 1 of 1

help needed, with while...

Posted: Wed May 10, 2006 1:50 pm
by allanre
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello!

Can somebody tell me pls whats wrong with this little piece of code?
It outputs: [ 1 ] ( 3 ) ( 2 ) [ 2 ] [ 3 ]
But it should: [ 1 ] ( 3 ) ( 2 ) [ 2 ] ( 3 ) ( 2 )[ 3 ]( 3 ) ( 2 )
im all out of ideas...

Code: Select all

while($row=mysql_fetch_array($answere))
    {  echo "[ ".$rida[eq_id]." ] ";
       
       
       while($row=mysql_fetch_array($answere2))
          {
       echo "( ".$rida2[eq_id]." ) ";

          
   
if($row[eq_id] == $row2[eq_id]) 
{


$AAA=checked;


break 1;




}

}
thanks.


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed May 10, 2006 3:43 pm
by Burrito
you're hitting the end of your resource in your second loop.

you'll need use a pointer to move the array back to the beginning.

take a look at mysql_data_seek()

Posted: Thu May 11, 2006 5:58 am
by allanre
thanks it helped.

Posted: Thu May 11, 2006 2:01 pm
by allanre
hello its me again, and this time i made very similar cycle like above and i got like twenty errors, can somebody explain me what could be the problem...

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 25 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 25 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 25 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 27 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 27 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 27 (or the query data is unbuffered) in /home/allanr/public_html/start/tunnid.php on line 679

Code: Select all

$ALL = mysql_query("SELECT eq_id, EQUIPMENT FROM DEVICES");
       $SELECTED = mysql_query("SELECT eq_id FROM KOMPOTT WHERE LESSON_ID= ".$row['Id']."");
          
      while($line=mysql_fetch_array($ALL)){
          //should output for example: 1 2 3 4 5 6 7 8
	   mysql_data_seek($VALITUD,0);
          while($line2=mysql_fetch_array($SELECTED)){
          //should output for example:  4 5 8
          if($line[eq_id]==$line2[eq_id]){
           echo "HUI";
             
            }

            }
}

Posted: Thu May 11, 2006 2:58 pm
by Burrito
the better solution would be to just save your second result set in an array and loop over the array. That way you're not hitting the server for each iteration of the loop.