<?php


$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "trabajoolasdatos";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully\n";

$allrubrics = mysqli_query($conn, 'select id, contents from `rubrics`');


$all_criterion_objectiveOutcome = mysqli_query($conn, 'select * from criterion_objective_outcome');

while ($row = mysqli_fetch_array($all_criterion_objectiveOutcome)) {
    $id = $row['id'];

    $criterion_id = $row['criterion_id'];



    $program_ids = mysqli_query($conn, "select * from program_criterion where criterion_id = {$criterion_id}");

    while ($prog_id = mysqli_fetch_array($program_ids)) {

        if ($prog_id['program_id'] != null) {
            $query = "insert into `program_criterion_objective_outcome` (`program_id`,`cri_obj_out_id`) values ({$prog_id['program_id']},{$id})";
            $makeQuery = mysqli_query($conn, $query);

            if (!$makeQuery) {
                die("Connection failed: " . mysqli_error($conn) . $query);
            }
        }
    }
}