Без опису

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. $servername = "127.0.0.1";
  3. $username = "root";
  4. $password = "";
  5. $database = "trabajoolas5";
  6. // Create connection
  7. $conn = mysqli_connect($servername, $username, $password, $database);
  8. // Check connection
  9. if (!$conn) {
  10. die("Connection failed: " . mysqli_connect_error());
  11. }
  12. echo "Connected successfully\n";
  13. $allrubrics = mysqli_query($conn, 'select id, contents from `rubrics`');
  14. while ($row = mysqli_fetch_array($allrubrics)) {
  15. foreach (json_decode($row['contents']) as $criterion) {
  16. $outcome_id = $criterion->outcome_id;
  17. $querySelect = "select * from rubric_outcome where rubric_id ={$row['id']} and outcome_id = {$outcome_id}";
  18. $makeQuery = mysqli_query($conn, $querySelect);
  19. if (!mysqli_num_rows($makeQuery)) {
  20. $query2 = "insert into `rubric_outcome` (`rubric_id`, `outcome_id`) values ({$row['id']}, {$outcome_id});";
  21. $makeQuery = mysqli_query($conn, $query2);
  22. if (!$makeQuery) {
  23. die("Connection failed: " . mysqli_error($conn) . $query2);
  24. }
  25. }
  26. $criteria_id = $criterion->id;
  27. $querySelect = "select * from rubric_criterion where rubric_id ={$row['id']} and criterion_id = {$criteria_id}";
  28. $makeQuery = mysqli_query($conn, $querySelect);
  29. if (!mysqli_num_rows($makeQuery)) {
  30. $query2 = "insert into `rubric_criterion` (`rubric_id`, `criterion_id`) values ({$row['id']}, {$criteria_id});";
  31. $makeQuery = mysqli_query($conn, $query2);
  32. if (!$makeQuery) {
  33. echo "Connection failed: " . mysqli_error($conn) . $query2;
  34. }
  35. }
  36. }
  37. }