2012-02-21 93 views
1

我試圖解決一個問題。我有一個索引頁面和用戶輸入開始和結束日期比按發送列表來這樣的:Php - 顯示日期只是一次

我想是顯示日期一樣,

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>"; 

這是我的代碼可以做些什麼改變?

謝謝。

enter image description here

回答

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

所以,如果我明白這個權利,那麼你想每個日期只顯示一次。那麼如何將日期保存在某個緩衝區變量中並檢查下一個日期是否相同。像這樣的東西。

$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>"; 
1

只需幾招即可完成您的要求。

在您的查詢中添加:order by "date field name"

,然後替換你的,而代碼:

$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. 
     } 

    } 

我想你可以這一招之下。