Php 第二个表的mysql结果与第一个表的行长度相同
我面临的问题是,我的治疗记录由6行数据组成,而我的即将到来的约会行仅由1行数据组成,但现在我的即将到来的约会行也复制为6行作为我的第一个表 以下是mysql代码:Php 第二个表的mysql结果与第一个表的行长度相同,php,database,pdo,Php,Database,Pdo,我面临的问题是,我的治疗记录由6行数据组成,而我的即将到来的约会行仅由1行数据组成,但现在我的即将到来的约会行也复制为6行作为我的第一个表 以下是mysql代码: if(empty($_GET['name'])) { echo 'Please don\'t try to hack!<br /><a href="./" title="Retry">Click here to <b>retry</b> again</a>'; e
if(empty($_GET['name'])) {
echo 'Please don\'t try to hack!<br /><a href="./" title="Retry">Click here to <b>retry</b> again</a>';
exit;
}
require_once 'dbconnect.php';
$p_id = $_GET['name'];
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = "SELECT *
FROM appointment a
LEFT JOIN customer c
ON a.customer_id = c.cust_id
AND a.deleted = '0'
LEFT JOIN services s
ON c.cust_id = s.customer_id
AND s.deleted = '0'
WHERE c.slug LIKE :id";
$q = $conn->prepare($sql);
$q->execute(array('id' => $p_id));
$q->setFetchMode(PDO::FETCH_ASSOC);
$cs = $q->fetchAll();
} catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
下面是我的html视图代码:
<div id="container">
<h1>Customer Record</h1>
Name: <?php echo htmlspecialchars($cs[0]['fname'].' '.$cs[0]['lname']); ?> <br />
Gender: <?php echo htmlspecialchars($cs[0]['gender']); ?> <br />
Mobile Number: <?php echo htmlspecialchars($cs[0]['number']); ?> <br /><br />
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Treatment</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($cs as $r):?>
<tr>
<td><?php if($r['treatment'] === NULL) { echo "No Record Found"; } else { echo htmlspecialchars($r['treatment']); } ?></td>
<td><?php if($r['date'] === NULL) { echo "No Record Found"; } else { echo htmlspecialchars($r['date']); } ?></td>
<td><?php if($r['service_id'] === NULL) { echo "No Record Found"; } else { ?><a href="editrecord.php?name=<?php echo htmlspecialchars($r['slug']) ?>&id=<?php echo htmlspecialchars($r['service_id']) ?>">Edit Record</a> or <a href="deleterecord.php?name=<?php echo htmlspecialchars($r['slug']) ?>&id=<?php echo htmlspecialchars($r['service_id']) ?>">Delete Record</a><?php } ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<thead>
<tr>
<th>Upcoming Appointment</th>
<th>Appointment Type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($cs as $r):?>
<tr>
<td><?php if($r['appt_date'] === NULL) { echo "No Record Found"; } else { echo htmlspecialchars($r['appt_date']); } ?></td>
<td><?php if($r['appointment_type'] === NULL) { echo "No Record Found"; } else { echo htmlspecialchars($r['appointment_type']); } ?></td>
<td><?php if($r['service_id'] === NULL) { echo "No Record Found"; } else { ?><a href="editrecord.php?name=<?php echo htmlspecialchars($r['slug']) ?>&id=<?php echo htmlspecialchars($r['service_id']) ?>">Edit Record</a> or <a href="deleterecord.php?name=<?php echo htmlspecialchars($r['slug']) ?>&id=<?php echo htmlspecialchars($r['service_id']) ?>">Delete Record</a><?php } ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="./">Seach Again</a><br /><br />
<a href="addrecord.php?name=<?php echo htmlspecialchars($r['slug']) ?>">Add Record</a>
</div>
我不确定哪里出错了,但我怀疑我的sql代码部分出错了
这是
这是
我需要这三个表数据来显示所有信息,如果我只使用约会表中的左连接,它在第6行上不会显示重复错误,但是如果我使用左连接约会表和左连接服务表,我的治疗表结果显示了6行,这是正确的,但我的下一个表也显示了6行相同的结果,而它在数据库中只有1行数据
请告诉我哪里出错了。请为每个Fiddle发布所需的结果。@PM77-1:实际上我只想要一个结果,两个Fiddle只显示sql查询方法。如果您引用它,则显示1个结果如果您引用它,则显示6个结果我希望在html视图中显示的内容处理日期操作显示六个结果和即将到来的约会约会类型操作使用第二小提琴仅显示1个结果而不是6个结果method@PM77-你能在这个问题上帮助我吗?我不是PHP程序员。如果您需要我对SQL部分的帮助,我希望看到您的查询结果添加到post纯数据中。