这是我的PHP代码:
$query4=mysql_query("select * from quiz
where `group`='$token'") or die(mysql_error());
while($row4=mysql_fetch_assoc($query4)){
echo $row4['quiz_no'];
}
我的桌子上有3排quiz_no 1 1 2
但我希望像这样显示:
Quiz no. 1 Quiz no. 2
但它一直显示
1 1 2
答案 0 :(得分:0)
您只需选择不同的对象。您的查询可以更改为:
select distinct quiz_no from quiz where `group`='$token'
请注意, 是执行数据库查询的安全方法,因为它受到SQL injection攻击。以下类似的东西将是首选:
$query = sprintf("select distinct quiz_no from quiz where `group`='%s'",
mysql_real_escape_string($token));
mysql_query($query);
如果你想达到你想要的输出,你需要回应“测验号”。手动:
echo "Quiz no. " . $row4['quiz_no'];
答案 1 :(得分:0)
只需添加字符串“Quiz no。”回声测验号并使用DISTINCT
<?php
$query4=mysql_query("select distinct * from quiz where `group`='$token'") or die(mysql_error());
while($row4=mysql_fetch_assoc($query4)){
echo "Quiz no. " . $row4['quiz_no'] ."\n";
}
?>