我尝试解决问题。我有一个索引页面,用户输入开始和结束日期比按下发送列表就是这样:
我想要的是显示那样的日期
30191592 Izlesene.com izlesene_kanal_v4_360 1
30191592 Izlesene.com izlesene_player_v4_240 1
30191592 Izlesene.com player_mydonose 4
30191592 Izlesene.com izlesene_sponsor_v4_360 16
30191592 Izlesene.com izlesene_player_v4_360 32
30191592 Izlesene.com izlesene_cihan_v4 152
30191592 Izlesene.com izlesene_vodafone_v3 1052
30191592 Izlesene.com izlesene_sponsor_v4 3099
30191592 Izlesene.com izlesene_kanal_v4 13727
30191592 Izlesene.com izlesene_player_v4 2144704
47335159 İzlesene Ntv izlesene_player_v4 2546
47335159 Cihanhaber izlesene_cihan_v4 8794 2012-02-21
30191592 Izlesene.com izlesene_sponsor_v4 3099
30191592 Izlesene.com izlesene_kanal_v4 13727
30191592 Izlesene.com izlesene_player_v4 2144704
47335159 İzlesene Ntv izlesene_player_v4 2546
47335529 İzlesene Cihanhaber izlesene_player_v4 2279
47335529 İzlesene Cihanhaber izlesene_cihan_v4 8794 2012-02-20
我的意思是我只想一次约会。
while ($info = mysql_fetch_array($dbResult)) {
$total+= $info['totalEvents'];
echo "<tr>";
echo "<td><input type=checkbox name='check1' id='check1' value='" . $info['eventCategory'] . "' onclick=recal(" . $info['totalEvents'] . ",this.checked) checked></td><td>" . $info['id'] . " " . $info['name'] . "</td>";
echo "<td>" . $info['eventCategory'] . "</td>";
echo "<td><id='totalEvents'>". $info['totalEvents'] . "</td>";
echo "<td>". $info['Date'] . "</td>";
}
echo "<td><b id='total'>" . $total . "</b></td>";
这是我的代码可以改变什么?
谢谢。
答案 0 :(得分:4)
只需检查日期是否与上一个相同。你可以这样做:
$previousDate = '';
while ($info = mysql_fetch_array($dbResult)) {
$total+= $info['totalEvents'];
echo "<tr>";
echo "<td><input type=checkbox name='check1' id='check1' value='" . $info['eventCategory'] . "' onclick=recal(" . $info['totalEvents'] . ",this.checked) checked></td><td>" . $info['id'] . " " . $info['name'] . "</td>";
echo "<td>" . $info['eventCategory'] . "</td>";
echo "<td><id='totalEvents'>". $info['totalEvents'] . "</td>";
if ($info['Date'] != $previousDate){
echo "<td>". $info['Date'] . "</td>";
} else {
echo "<td></td>";
}
$previousDate = $info['Date'];
}
echo "<td><b id='total'>" . $total . "</b></td>";
答案 1 :(得分:1)
因此,如果我理解这一点,那么您只想显示每个日期一次。那么如何在一些缓冲区变量中保存日期并检查下一个日期是否相同。像这样的东西。
$buff = "";
while ($info = mysql_fetch_array($dbResult)) {
$total+= $info['totalEvents'];
echo "<tr>";
echo "<td><input type=checkbox name='check1' id='check1' value='" . $info['eventCategory'] . "' onclick=recal(" . $info['totalEvents'] . ",this.checked) checked></td><td>" . $info['id'] . " " . $info['name'] . "</td>";
echo "<td>" . $info['eventCategory'] . "</td>";
echo "<td><id='totalEvents'>". $info['totalEvents'] . "</td>";
if ($info['Date'] != $buff)
{
echo "<td>". $info['Date'] . "</td>";
$buff = $info['Date'];
}
else
{
echo "<td></td>";
}
}
echo "<td><b id='total'>" . $total . "</b></td>";
答案 2 :(得分:1)
只需几个技巧即可完成您的要求。
添加您的查询:order by "date field name"
。
然后将您的while代码替换为:
$tempDate;
while ($info = mysql_fetch_array($dbResult)) {
if($tempDate == $info['totalEvents']) {
//do that you want like merge the data of same date.
} else {
$tempDate = $info['totalEvents'];
// create new row.
}
}
我认为你可以根据这个伎俩。