conference_id links $q1 = mysql_query("SELECT year, id FROM conferences WHERE year>0"); while($r = mysql_fetch_assoc($q1)){ foreach($tables as $tableName){ $query = "UPDATE `$tableName` SET `conferences_id` = {$r['id']} WHERE `year` = {$r['year']}"; mysql_query($query); echo $query . ";\n"; } } // a couple more foreach($tables as $tableName){ $query = "UPDATE `$tableName` SET `conferences_id` = -1 WHERE `year` = -1"; mysql_query($query); echo $query . ";\n"; $query = mysql_query("SELECT DISTINCT(year) FROM `$tableName` WHERE `conferences_id` = 0"); $badYears = array(); while($data = mysql_fetch_assoc($query)){ $badYears[] = $data['year']; } if(count($badYears) > 0){ echo "ERROR: could not update conference_id in the table '$tableName' for the years "; echo implode(', ', $badYears) . "\n"; } } } ?>