$query="SELECT * FROM cse_routine WHERE batch ='$batch' and section='$section' order by 'day'";
$post = $db->select($query);
?>
<?php
if ($post) {
while ($result = $post->fetch_assoc()) {
$var = "select * from cse_routine where day = '".$result['day'] ."'";
print $result['day']."<br>";
if ($results=$db->select($var))
{
while ($rows = mysqli_fetch_assoc($results))
{
print $rows['t_slot']. " " . $rows['room']. " " . $rows['day']. " " . $rows['c_code'];
echo "<br>";
}
}
echo "<br>";
}
}
echo "<br>";
?>
运行此代码;我发现了这个:
没关系。但实际上,我希望输出不会重复打印相同的日期。在这里看到星期六,星期日打印3他们每个但我想要星期六打印1和星期日打印1。
答案 0 :(得分:2)
您只需将查询更改为
即可$query="SELECT * FROM cse_routine WHERE batch ='$batch' and section='$section'
GROUP by 'day'";
答案 1 :(得分:0)
您可以尝试在第一个SQL中使用DISTINCT约束(http://www.mysqltutorial.org/mysql-distinct.aspx):
$query="SELECT DISTINCT day FROM cse_routine WHERE batch ='$batch' and section='$section' order by 'day'";
所以你每周六和周日只有一次。