这是我第一次在SO发帖,如果我打开一个存在的问题,我很抱歉。因为我无法在Google中找到结果。对不起,但我仍然在PHP PDO和学习阶段新鲜。PHP PDO,虽然没有达到我的愿望最终结果
回到我的问题,目前我正在建立一个来自我妻子的客户访问日志,但我坚持的结果。我有两个表,其中一个存储客户信息,另一个表存储访问详细信息。我上传在这里的测试表:SQL Fiddle
及以下是我目前的编码和我使用PHP PDO 而
<?php
require_once 'dbconnect.php';
$p_id = $_GET['name'];
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = "SELECT customer.fname, customer.lname, customer.gender, services.treatment, services.date
FROM customer LEFT JOIN services
ON customer.id = services.customer_id
WHERE customer.slug LIKE :id";
$q = $conn->prepare($sql);
$q->execute(array('id' => $p_id));
$q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="container">
<h1>Customer Record</h1>
Name: <br />
Gender: <br />
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Customer Name</th>
<th>Customer Gender</th>
<th>Treatment</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php while ($r = $q->fetch()): ?>
<tr>
<td><?php echo htmlspecialchars($r['fname']), ' ', htmlspecialchars($r['lname'])?></td>
<td><?php echo htmlspecialchars($r['gender']); ?></td>
<td><?php echo htmlspecialchars($r['treatment']); ?></td>
<td><?php echo htmlspecialchars($r['date']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<a href="search.html">Seach Again</a>
</body>
</div>
</html>
我作为实现哪些SQL小提琴的结果,但我想要的是,名称和性别不会重复。
我想是因为每截图图像,名称:李四和性别:男性,应该是在上面,而不是保持
我有截图连接在一起重复,而下面的表格显示所有的访问细节。我试图修改代码,但它似乎并没有真正解决。
请告诉我,我真的不知道如何实现我想要的。
非常感谢。
谢谢@ joseph8th它现在解决了我的问题:) – 2014-09-06 20:04:56
很高兴我可以帮助! – Joseph8th 2014-09-06 20:15:30