Brak opisu

script_template_scales_to_scales.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 `templates`');
  14. while ($row = mysqli_fetch_array($allrubrics)) {
  15. foreach (json_decode($row['contents']) as $criterion) {
  16. $criterion_id = $criterion->id;
  17. $querySelect = "select * from template_criterion where template_id ={$row['id']} and criterion_id = {$criterion_id}";
  18. $makeQuery = mysqli_query($conn, $querySelect);
  19. if (mysqli_num_rows($makeQuery)) {
  20. $row2 = mysqli_fetch_array($makeQuery);
  21. $template_criterion_id = $row2['id'];
  22. $description12 = mysqli_escape_string($conn, $criterion->description12);
  23. $queryForScale = "insert into scales (`description`, `min_score`, `max_score`) values ('{$description12}', 1, 2)";
  24. $makeQueryForScale = mysqli_query($conn, $queryForScale);
  25. if ($makeQueryForScale) {
  26. $toFindScale = "select * from scales order by id DESC";
  27. $findScale = mysqli_query($conn, $toFindScale);
  28. if (mysqli_num_rows($findScale)) {
  29. $scale = mysqli_fetch_array($findScale);
  30. $queryToInsert = "insert into `template_criterion_scale` (`template_criterion_id`,`scale_id`, `position`) values ({$template_criterion_id}, {$scale['id']}, 0)";
  31. $insertIntoTemplate = mysqli_query($conn, $queryToInsert);
  32. if (!$insertIntoTemplate) {
  33. echo "Scales problem: " . mysqli_error($conn) . $queryToInsert;
  34. die;
  35. }
  36. }
  37. } else {
  38. echo "Couldnt insert scale: " . mysqli_error($conn) . $queryForScale;
  39. die;
  40. }
  41. $description34 = mysqli_escape_string($conn, $criterion->description34);
  42. $queryForScale = "insert into scales (`description`, `min_score`, `max_score`) values ('{$description34}', 3, 4)";
  43. $makeQueryForScale = mysqli_query($conn, $queryForScale);
  44. if ($makeQueryForScale) {
  45. $toFindScale = "select * from scales order by id DESC";
  46. $findScale = mysqli_query($conn, $toFindScale);
  47. if (mysqli_num_rows($findScale)) {
  48. $scale = mysqli_fetch_array($findScale);
  49. $queryToInsert = "insert into `template_criterion_scale` (`template_criterion_id`,`scale_id`, `position`) values ({$template_criterion_id}, {$scale['id']}, 1)";
  50. $insertIntoTemplate = mysqli_query($conn, $queryToInsert);
  51. if (!$insertIntoTemplate) {
  52. echo "Scales problem: " . mysqli_error($conn) . $queryToInsert;
  53. die;
  54. }
  55. }
  56. } else {
  57. echo "Couldnt insert scale: " . mysqli_error($conn) . $queryForScale;
  58. die;
  59. }
  60. $description56 = mysqli_escape_string($conn, $criterion->description56);
  61. $queryForScale = "insert into scales (`description`, `min_score`, `max_score`) values ('{$description56}', 5, 6)";
  62. $makeQueryForScale = mysqli_query($conn, $queryForScale);
  63. if ($makeQueryForScale) {
  64. $toFindScale = "select * from scales order by id DESC";
  65. $findScale = mysqli_query($conn, $toFindScale);
  66. if (mysqli_num_rows($findScale)) {
  67. $scale = mysqli_fetch_array($findScale);
  68. $queryToInsert = "insert into `template_criterion_scale` (`template_criterion_id`,`scale_id`, `position`) values ({$template_criterion_id}, {$scale['id']}, 2)";
  69. $insertIntoTemplate = mysqli_query($conn, $queryToInsert);
  70. if (!$insertIntoTemplate) {
  71. echo "Scales problem: " . mysqli_error($conn) . $queryToInsert;
  72. die;
  73. }
  74. }
  75. } else {
  76. echo "Couldnt insert scale: " . mysqli_error($conn) . $queryForScale;
  77. die;
  78. }
  79. $description78 = mysqli_escape_string($conn, $criterion->description78);
  80. $queryForScale = "insert into scales (`description`, `min_score`, `max_score`) values ('{$description78}', 7, 8)";
  81. $makeQueryForScale = mysqli_query($conn, $queryForScale);
  82. if ($makeQueryForScale) {
  83. $toFindScale = "select * from scales order by id DESC";
  84. $findScale = mysqli_query($conn, $toFindScale);
  85. if (mysqli_num_rows($findScale)) {
  86. $scale = mysqli_fetch_array($findScale);
  87. $queryToInsert = "insert into `template_criterion_scale` (`template_criterion_id`,`scale_id`, `position`) values ({$template_criterion_id}, {$scale['id']}, 3)";
  88. $insertIntoTemplate = mysqli_query($conn, $queryToInsert);
  89. if (!$insertIntoTemplate) {
  90. echo "Scales problem: " . mysqli_error($conn) . $queryToInsert;
  91. die;
  92. }
  93. }
  94. } else {
  95. echo "Couldnt insert scale: " . mysqli_error($conn) . $queryForScale;
  96. die;
  97. }
  98. } else {
  99. echo "no creo que hay problema no?";
  100. }
  101. }
  102. }