2012-05-18 35 views
0

,我們有我們的循環出現問題了,當我們使用if語句那隻能說明我們的遊戲之一,而不是全部需要做日曆

的,這是我們的代碼:

$sqldayshours = mysqli_query($link, "SELECT * FROM event;") or die("Kon de comments niet ophalen"); 
$event_time = mysqli_fetch_assoc($sqldayshours); 

$title = $event_time['event_title']; 
    $day = $event_time['event_date_day']; 
    $uur = $event_time['event_date_hour']; 
    $ide = $event_time['event_id']; 
    $idsql="day".$day."uur".$uur; 

for($rij=8;$rij<19;$rij++) 
    { 
     echo " <tr> "; 
        for($i=0;$i<8;$i++) 
      { 
        $id = "day".$i."uur".$rij; 
        echo " < td id=\"$id\" name=\"$id\" class=\"events\">"; 
        if($i==0){ 
       echo $rij.":00 "; 
        }else{ 
            if($idsql == $id){ 
            echo $title; 
           } 
       } 
     echo "</td>"; 
       }` 

     echo "</tr>"; 

    } 
+2

那麼最新的問題? – Drewdin

+0

內在如果是問題。 –

+0

我想在日曆中顯示所有事件,並且如果我只顯示一個事件。我試圖使用循環,但從來沒有把它做對你有一個人有答案? – Ched

回答

0

唐「知道,如果這是你要找的,但你可以通過全部使用像這樣的結果循環:

<?php 

    while($event_time = mysqli_fetch_array($sqldayshours)) { 

     echo $event_time['title']; // or whatever you need to do. 

    } 

    //or alternatively 

    while($event_time = mysqli_fetch_array($sqldayshours)) { 

     $results[] = $event_time; 

    } 

    print_r($results); 

這允許您遍歷結果和你想和他們什麼。

第二個將結果推送到一個數組,然後您可以使用while循環之外的值或任何您想要執行的操作。

+0

是的,我得到了那麼多,但問題是獲得表中的每個相應的單元格中的$ title當我這樣做,如果它只顯示我在那裏它被列爲是,但不會爲下一個的 – Ched

0
<?php 

    $sqldayshours = mysqli_query($link, "SELECT * FROM event;") or die("Kon de comments niet ophalen"); 
    while($event_time = mysqli_fetch_array($sqldayshours)) { 
     for($rij=8;$rij<19;$rij++) 
    { 
     echo " <tr> "; 
        for($i=0;$i<8;$i++) 
      { 
        $id = "day".$i."uur".$rij; 
        echo " < td id=\"$id\" name=\"$id\" class=\"events\">"; 
        if($i==0){ 
       echo $rij.":00 "; 
        }else{ 
            if($idsql == $id){ 
            echo $event_time['title']; 
           } 
       } 
     echo "</td>"; 
       }` 

     echo "</tr>"; 

    } 
    } 

?> 
+0

現在它循環所有的表,以及也許問題是如果 – Ched

0
<?php 

$sqldayshours = mysqli_query($link, "SELECT * FROM event;") or die("Kon de comments niet ophalen"); 

//loop all 18hours of one day 
for($hour=8;$hour<19;$hour++) 
{ 
    echo "<tr>"; 

    //loop all 7days 
    for($day=0;$day<8;$day++) 
    { 
     //save the current time in the loop 
     $current_time = "day".$day."uur".$hour; 

     //loop all the events in the query and check for a valid one 
     while($one_event = $sqldayshours->fetch_array()) 
     { 
      $title = $one_event['event_title']; 
      $day2= $one_event['event_date_day']; 
      $hour2= $one_event['event_date_hour']; 
      $id2 = $one_event['event_id']; 
      $idsql = "day".$day2."uur".$hour2; 

      echo "<td id='$current_time' name='$current_time' class='events'>"; 

      if($day == 0) 
      { 
       echo $hour.":00"; 
       echo "</td>"; 
      } 
      else if($current_time == $idsql) 
      { 
       echo $title; 
       echo "</td>"; 
      } 
      else 
      { 
       echo "</td>"; 
      } 
     } 

    echo "<tr>"; 

    } 
} 

?> 

我調轉循環。這可能會在服務器上承擔更高的負載,但是對於您生成的每一行,他會檢查它們是否是數據庫中的有效條目,如果不是,他繼續。 希望我有道理。我沒有測試過這個,只是寫了我的想法。但是你可能會找到靈感或其他東西。

我也試圖按照你的邏輯...

Madjdc。

+0

後大量tweeking它仍然沒有讓我所有的記錄在那裏 – Ched