help needed, with while...

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
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

help needed, with while...

Post 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]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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()
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

Post by allanre »

thanks it helped.
allanre
Forum Newbie
Posts: 9
Joined: Wed May 10, 2006 1:40 pm

Post 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";
             
            }

            }
}
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

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