Multiple WHILE clauses not running

I have a problem running multiple ‘While’ queries.

my code so far is:


for($a = 0; $a <sizeof($slaveRes_array); $a++) 	{
	$con = mysql_connect($slaveRes_array[$a]['server'], $slaveRes_array[$a]['user'], $slaveRes_array[$a]['password']); 
	mysql_select_db($dbs, $con);      
	for($b = 0; $b <sizeof($query_array); $b++) {
		$slaveState = mysql_query($query_array[$b]['query1'], $con); 
			
// FIRST WHILE QUERY
			while(($slave_array2[] = mysql_fetch_assoc($slaveState)) || array_pop($slave_array2));

// SECOND WHILE QUERY
			while($row = mysql_fetch_assoc($slaveState)) {
				if (($row['Slave_IO_Running'] == "No") || ($row['Slave_IO_Running'] == "Yes")) {
					$slave_array[]['name'] = $slaveRes_array[$a]['database'];}	
				 else { print "nothing";};
				}
				}
        		}

The problem is that the first one executes, but not the second. If I swap them over, the same thing (first one is OK, second one desn’t run).
what am I missing?

$slaveRes_array is an array with a list of servers, and their connection details.
$query_array is a list of MySQL queries to run against each database (only one query is listed at the moment)

The idea being to open a connection to a database, run a series of queries, and save each of those queries to an array for later use, and then move on to the next server and do the same thing again.

Maybe you need to look in the manual as to how mysql_fetch_assoc works. Basically it sets the pointer to the default, 0, then increases it by one for every row it fetches. Therefore if you ran the function 5 times (not with a while loop) it will fetch 5 rows respectively.

As for solving your issue, you need to reset that pointer to 0 again.

mysql_data_seek

cheers, I tried adding


mysql_data_seek($slaveState,0);

in between the two WHILE clauses, but that then gave me:

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 7 (or the query data is unbuffered) in C:\wamp\www\ s\slaveQuery.php on line 32

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 28 (or the query data is unbuffered) in C:\wamp\www\ s\slaveQuery.php on line 32