$location_id) { echo("sensor_id=$sensor_id, location_id=$location_id\n"); if (!$location_id) { echo("no location_id given for sensor_id, skipping\n"); continue; } //find last measurement for location $last_log_id = db_single_field(<<= first_log_id AND log.log_id < next_log_id WHERE location_id = $location_id EOQ ); if ($last_log_id > $late_log_id) fatal("impossible, \$last_log_id = $last_log_id must be <= \$late_log_id = $late_log_id"); echo("last_log_id=$last_log_id\n"); if ($last_log_id) $prev_meaning_id = db_single_field(<<= first_log_id AND log.log_id < next_log_id WHERE log_id = $last_log_id EOQ ); else $prev_meaning_id = NULL; echo("prev_meaning_id=".($prev_meaning_id?$prev_meaning_id:'NULL')."\n"); db_exec('INSERT INTO meaning ( location_id, sensor_id, first_log_id, prev_meaning_id ) VALUES ( ?, ?, ?, ? )', $location_id, $sensor_id, $last_log_id + 1, $prev_meaning_id); } header("Location: index.php"); ?>