在网页中显示mysql中的两个数据库时出现问题

kmbjn2e3  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(318)

我在网页中显示两个数据库时遇到问题。我有一个数据库,用户可以在其中创建一个名为“tickets”的新“ticket”,当该ticket标记为“pending”时,它会将数据库条目移动到一个名为“out\u tickets”的新数据库表中。所以在我的index.php页面上,我有一个 Jmeter 板视图来显示新的“票据”以及“待定”票据。但是现在我很难在index.php上显示来自数据库的“待定”票证结果。
这是我的密码:

  1. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  2. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  3. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
  4. <style type="text/css">
  5. .wrapper{
  6. width: 0 auto;
  7. margin: 0 auto;
  8. }
  9. .page-header h2{
  10. margin-top: 0;
  11. }
  12. table tr td:last-child a{
  13. margin-right: 15px;
  14. }
  15. </style>
  16. <script type="text/javascript">
  17. $(document).ready(function(){
  18. $('[data-toggle="tooltip"]').tooltip();
  19. });
  20. </script>
  21. </p>
  22. <body>
  23. <div class="wrapper">
  24. <div class="container-fluid">
  25. <div class="row">
  26. <div class="col-md-12">
  27. </div>
  28. <?php
  29. // Include config file
  30. require_once 'config.php';
  31. // Attempt select query execution
  32. $sql = "SELECT * FROM tickets";
  33. if($result = mysqli_query($link, $sql)){
  34. if(mysqli_num_rows($result) > 0){
  35. echo "<table class='table table-bordered table-striped'>";
  36. echo "<thead>";
  37. echo "<tr>";
  38. echo "<th>#</th>";
  39. echo "<th>Name</th>";
  40. echo "<th>Address</th>";
  41. echo "<th>Contact Details</th>";
  42. echo "<th>Email</th>";
  43. echo "<th>Job Type</th>";
  44. echo "<th>Description</th>";
  45. echo "<th>Action</th>";
  46. echo "</tr>";
  47. echo "</thead>";
  48. echo "<tbody>";
  49. while($row = mysqli_fetch_array($result)){
  50. echo "<tr>";
  51. echo "<td>" . $row['id'] . "</td>";
  52. echo "<td>" . $row['client_name'] . "</td>";
  53. echo "<td>" . $row['client_address'] . "</td>";
  54. echo "<td>" . $row['client_contact'] . "</td>";
  55. echo "<td>" . $row['client_email'] . "</td>";
  56. echo "<td>" . $row['client_jobtype'] . "</td>";
  57. echo "<td>" . $row['client_description'] . "</td>";
  58. echo "<td>";
  59. echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
  60. echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
  61. echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
  62. echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
  63. echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
  64. echo "</td>";
  65. echo "</tr>";
  66. }
  67. echo "</tbody>";
  68. echo "</table>";
  69. // Free result set
  70. mysqli_free_result($result);
  71. } else{
  72. echo "<p class='lead'><em>No records were found.</em></p>";
  73. }
  74. } else{
  75. echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  76. }
  77. // Close connection
  78. mysqli_close($link);
  79. ?>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. <h1 style="font-size:25px;
  85. background-color:darkgray;
  86. border:2px solid black;
  87. text-align:center">
  88. Outstanding Tasks
  89. </h1>
  90. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  91. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  92. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
  93. <style type="text/css">
  94. .wrapper{
  95. width: 0 auto;
  96. margin: 0 auto;
  97. }
  98. .page-header h2{
  99. margin-top: 0;
  100. }
  101. table tr td:last-child a{
  102. margin-right: 15px;
  103. }
  104. </style>
  105. <script type="text/javascript">
  106. $(document).ready(function(){
  107. $('[data-toggle="tooltip"]').tooltip();
  108. });
  109. </script>
  110. </p>
  111. <body>
  112. <div class="wrapper">
  113. <div class="container-fluid">
  114. <div class="row">
  115. <div class="col-md-12">
  116. </div>
  117. <?php
  118. require_once 'config.php';
  119. // Attempt select query execution
  120. $sql = "SELECT * FROM out_tickets";
  121. if($result = mysqli_query($link, $sql)){
  122. if(mysqli_num_rows($result) > 0){
  123. echo "<table class='table table-bordered table-striped'>";
  124. echo "<thead>";
  125. echo "<tr>";
  126. echo "<th>#</th>";
  127. echo "<th>Name</th>";
  128. echo "<th>Address</th>";
  129. echo "<th>Contact Details</th>";
  130. echo "<th>Email</th>";
  131. echo "<th>Job Type</th>";
  132. echo "<th>Description</th>";
  133. echo "<th>Action</th>";
  134. echo "</tr>";
  135. echo "</thead>";
  136. echo "<tbody>";
  137. while($row = mysqli_fetch_array($result)){
  138. echo "<tr>";
  139. echo "<td>" . $row['id'] . "</td>";
  140. echo "<td>" . $row['client_name'] . "</td>";
  141. echo "<td>" . $row['client_address'] . "</td>";
  142. echo "<td>" . $row['client_contact'] . "</td>";
  143. echo "<td>" . $row['client_email'] . "</td>";
  144. echo "<td>" . $row['client_jobtype'] . "</td>";
  145. echo "<td>" . $row['client_description'] . "</td>";
  146. echo "<td>";
  147. echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
  148. echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
  149. echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
  150. echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
  151. echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
  152. echo "</td>";
  153. echo "</tr>";
  154. }
  155. echo "</tbody>";
  156. echo "</table>";
  157. // Free result set
  158. mysqli_free_result($result);
  159. } else{
  160. echo "<p class='lead'><em>No records were found. </em></p>";
  161. }
  162. } else{
  163. echo "ERROR: Could not able to execute $sql. " .
  164. mysqli_error($link);
  165. }
  166. // Close connection
  167. mysqli_close($link);
  168. ?>
  169. </div>
  170. </div>
  171. </div>
  172. </div>

正如你看到的第一个 $sql = "SELECT * FROM tickets"; 行,但这个不行 $sql = "SELECT * FROM out_tickets"; 我在mysql中有这两个数据库,可以从phpmyadmin中看到其中的数据
这是我得到的错误:

  1. Warning: mysqli_query(): Couldn't fetch mysqli in
  2. C:\index.php on line 211
  3. Warning: mysqli_error(): Couldn't fetch mysqli in
  4. C:\index.php on line 254
  5. ERROR: Could not able to execute SELECT * FROM out_tickets.
  6. Warning: mysqli_close(): Couldn't fetch mysqli in
  7. C:\index.php on line 258
cld4siwp

cld4siwp1#

你说过有两个数据库里面有特定的表。我以前看过你的代码 SELECT * FROM out_tickets 等分线 require_once 'config.php'; . 你必须连接到另一个数据库(根据你的话判断)。

umuewwlo

umuewwlo2#

我认为config.php只连接到第一个数据库。您只需将另一个连接字符串设置到另一个数据库,将其命名为$link\u 2,并在查询out\u票证时使用$link\u 2即可

相关问题