conference_id links $q1 = mysql_query("SELECT year, id FROM conferences WHERE year>0"); $tables=array("projectdivisions","projectsubdivisions","projectcategories","projectcategoriesdivisions_link"); //update the tables 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"; } } } ?>