我在网页中显示两个数据库时遇到问题。我有一个数据库,用户可以在其中创建一个名为“tickets”的新“ticket”,当该ticket标记为“pending”时,它会将数据库条目移动到一个名为“out\u tickets”的新数据库表中。所以在我的index.php页面上,我有一个 Jmeter 板视图来显示新的“票据”以及“待定”票据。但是现在我很难在index.php上显示来自数据库的“待定”票证结果。
这是我的密码:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<style type="text/css">
.wrapper{
width: 0 auto;
margin: 0 auto;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</p>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM tickets";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Contact Details</th>";
echo "<th>Email</th>";
echo "<th>Job Type</th>";
echo "<th>Description</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['client_name'] . "</td>";
echo "<td>" . $row['client_address'] . "</td>";
echo "<td>" . $row['client_contact'] . "</td>";
echo "<td>" . $row['client_email'] . "</td>";
echo "<td>" . $row['client_jobtype'] . "</td>";
echo "<td>" . $row['client_description'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</div>
</div>
</div>
</div>
<h1 style="font-size:25px;
background-color:darkgray;
border:2px solid black;
text-align:center">
Outstanding Tasks
</h1>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<style type="text/css">
.wrapper{
width: 0 auto;
margin: 0 auto;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</p>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
</div>
<?php
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM out_tickets";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Contact Details</th>";
echo "<th>Email</th>";
echo "<th>Job Type</th>";
echo "<th>Description</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['client_name'] . "</td>";
echo "<td>" . $row['client_address'] . "</td>";
echo "<td>" . $row['client_contact'] . "</td>";
echo "<td>" . $row['client_email'] . "</td>";
echo "<td>" . $row['client_jobtype'] . "</td>";
echo "<td>" . $row['client_description'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found. </em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " .
mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</div>
</div>
</div>
</div>
正如你看到的第一个 $sql = "SELECT * FROM tickets";
行,但这个不行 $sql = "SELECT * FROM out_tickets";
我在mysql中有这两个数据库,可以从phpmyadmin中看到其中的数据
这是我得到的错误:
Warning: mysqli_query(): Couldn't fetch mysqli in
C:\index.php on line 211
Warning: mysqli_error(): Couldn't fetch mysqli in
C:\index.php on line 254
ERROR: Could not able to execute SELECT * FROM out_tickets.
Warning: mysqli_close(): Couldn't fetch mysqli in
C:\index.php on line 258
2条答案
按热度按时间cld4siwp1#
你说过有两个数据库里面有特定的表。我以前看过你的代码
SELECT * FROM out_tickets
等分线require_once 'config.php';
. 你必须连接到另一个数据库(根据你的话判断)。umuewwlo2#
我认为config.php只连接到第一个数据库。您只需将另一个连接字符串设置到另一个数据库,将其命名为$link\u 2,并在查询out\u票证时使用$link\u 2即可