我的数据库表“resbook”中有以下数据
htno name fname
2 Rakesh Rahul
2 Rakesh Rahul
2 Rakesh Rahul
2 Rakesh Rahul
2 Rakesh Rahul
3 Himesh Krishna
3 Himesh Krishna
3 Himesh Krishna
3 Himesh Krishna
3 Himesh Krishna
我有一个表单要求用户输入“htno”,并且我只想为相应的“htno”显示一次“名称”和“fname”,因为相同的行重复了五次
这是我的代码
<?PHP
$userInputEntities = htmlentities($userInput);
echo $userInputEntities;
$username = "admin";
$password = "123456";
$database = "resbook";
$server = "localhost";
$db = new PDO ("mysql:host=$server;dbname=$database", "$username", "$password");
if ($db) {
$id = $_GET['id'];
$NAME = $db->prepare("SELECT * FROM resbook WHERE htno=:id");
$NAME -> execute(array(':id'=>$id));
while ($row1 = $NAME->fetch(PDO::FETCH_ASSOC)){
echo "<td align=left><font size='2'> STUDENT NAME :</font><font color='blue' size='2'><b> " . $row1['name']. "</b></font></td>";
echo "<strong>  ||  </strong>";
echo "<td align=left><font size='2'> FATHER NAME :</font><font color='blue' size='2'><b> " . $row1['fname']. "</b><p></font></td>";
}
使用此代码,我将输出重复 5 次,因为表中的每个 htno 有 5 行
STUDENT NAME : Rakesh || FATHER NAME : Rahul
STUDENT NAME : Rakesh || FATHER NAME : Rahul
STUDENT NAME : Rakesh || FATHER NAME : Rahul
STUDENT NAME : Rakesh || FATHER NAME : Rahul
STUDENT NAME : Rakesh || FATHER NAME : Rahul
我只想像这样输出一次
STUDENT NAME : Rakesh || FATHER NAME : Rahul
请帮帮我