2014-01-14 88 views
0

這裏我沒有任何編碼相關的問題。我試圖從多個數據庫表中獲取細節。取結果工作正常。但對齊是我的問題在這裏。對齊問題在PHP while循環

enter image description here

你可以看到一個圖像。在該圖像憑證狀態欄工作正常。但是,另外兩列(房間狀態&膳食狀態值)總是在最後一行。如何正確對齊這些(房間和膳食狀態)值(如優惠券狀態欄)?我希望你能理解我的問題......

 <?php 
     echo "<table width=1090 border=1 style=\"border: #ddd;\" align=center cellspacing=4 cellpadding=10>"; 
     echo "<tr class=thvoucher>"; 
     echo "<th width=30>Voucher Number</th>"; 
     echo "<th width=80>Reference Number</th>"; 
     echo "<th width=200>Guest Name</th>"; 
     echo "<th width=150>Voucher Status</th>"; 
     echo "<th width=150>Room Status</th>"; 
     echo "<th width=150>Meal Status</th>"; 
     echo "</tr>"; 
     for($i = $start; $i < $end; $i++) 
     { 
      if ($i == $total_results) 
      { 
       break; 
      } 
      while($row = $stmt->fetch()) 
      { 
       $voucherid = $row['VoucherID']; 
      $ref = $row['VoucherReference']; 
      $gname = $row['GuestName']; 
      $vstatus = $row['ActiveStatus']; 
      echo "<tr class=voucherstyle" . $cls . ">"; 
      echo "<td>$voucherid</td>"; **// FIRST TD** 
      echo "<td>$ref</td>"; **// SECOND TD** 
      echo "<td>$gname</td>";  **// THIRD TD** 

         if($vstatus != 'empty')  **// FOURTH TD** 
     { 
      if($vstatus == 'Y') 
      { 
       echo "<td class=green >Active</td>"; 
      } 
      else if($vstatus == 'N') 
      { 
       echo "<td class=red >Inactive</td>"; 
      } 
     } 
     else 
      { 
       echo "<td><form method=post onsubmit=\"return mstatusvalidate(this)\"; action='voucherstatus_update.php?id_meal= $voucherid '><select name=mealstatus><option value=empty></option><option value=active>Active</option><option value=inactive>Inactive</option></select><input type=submit class=update_status title=\"Update $gname voucher status\" value=Update></form></td>"; 
      } 
      } 

      while($r_row = $r_stmt->fetch()) 
      { 
       $rstatus = $r_row['ActiveStatus']; 

         // same like above if else statement  **// FIFTH TD** 
      }  

      while($m_row = $m_stmt->fetch()) 
      { 
       $mstatus = $m_row['ActiveStatus']; 

         // same like above if else statement **// SIXTH TD**  
      } 
echo "</tr>"; 
      } 
      echo "</table>"; 
      ?> 
+0

你不關閉你的循環內的標籤。此外,你宣佈6個冠軍。但其中只有3輸出。 – Yami

+0

您發佈的代碼似乎沒有爲您在對齊時遇到的單元格發射任何HTML。我看不出我們能從中得到什麼幫助。 – 2014-01-14 07:11:15

+0

@Yami:我用了6個TD。我沒有發佈如果其他語句代碼在這裏。所以,只有你沒有看到剩餘的td。我用另外3個td在if if語句中。我已更新我的代碼。再見 – Karuppiah

回答

0

我得到它的工作使用這個條件時while(($row = $stmt->fetch()) && ($r_row = $r_stmt->fetch()) && ($m_row = $m_stmt->fetch()))。在我使用三個單獨的while循環之前。現在,我有一些其他的想法。我試了一下,現在它的工作正常並且對齊也很完美。在我沒有發佈我的if else語句代碼之前。所以,每個人都認爲我只用了3臺。對不起,迷惑大家...我已經張貼了我下面的編碼正確..

 <?php 
     echo "<table width=1090 border=1 style=\"border: #ddd;\" align=center cellspacing=4 cellpadding=10>"; 
     echo "<tr class=thvoucher>"; 
     echo "<th width=30>Voucher Number</th>"; 
     echo "<th width=80>Reference Number</th>"; 
     echo "<th width=200>Guest Name</th>"; 
     echo "<th width=150>Voucher Status</th>"; 
     echo "<th width=150>Room Status</th>"; 
     echo "<th width=150>Meal Status</th>"; 
     echo "</tr>"; 
     for($i = $start; $i < $end; $i++) 
     { 
      if ($i == $total_results) 
      { 
       break; 
      } 
      while(($row = $stmt->fetch()) && ($r_row = $r_stmt->fetch()) && ($m_row = $m_stmt->fetch())) 
      { 
       $voucherid = $row['VoucherID']; 
       $ref = $row['VoucherReference']; 
       $gname = $row['GuestName']; 
       $vstatus = $row['ActiveStatus']; 
       echo "<tr class=voucherstyle" . $cls . ">"; 
       echo "<td>$voucherid</td>";  **1st TD** 
       echo "<td>$ref</td>";  **2nd TD** 
       echo "<td>$gname</td>";  **3rd TD** 
       if($vstatus != 'empty')  **4th TD** 
       { 
        if($vstatus == 'Y') 
        { 
         echo "<td class=green >Active</td>"; 
        } 
        else if($vstatus == 'N') 
        { 
         echo "<td class=red >Inactive</td>"; 
        } 
       } 
       else 
        { 
         echo "<td><form method=post onsubmit=\"return mstatusvalidate(this)\"; action='voucherstatus_update.php?id= $voucherid '><select name=mealstatus><option value=empty></option><option value=active>Active</option><option value=inactive>Inactive</option></select><input type=submit class=update_status title=\"Update $gname voucher status\" value=Update></form></td>"; 
        } 

       $rstatus = $r_row['ActiveStatus']; 
       // if else statement  **5th TD** 

       $mstatus = $m_row['ActiveStatus']; 
       // if else statement  **6th TD** 
       echo "</tr>"; 
      } 
     } 
     echo "</table>"; 
     ?> 
2

你有你的第一行中的第6個元素,但我只看到後續行3個td元素也沒有TR結束標記。這可能是你的問題。

我會懷疑對源輸出進行粗略檢查會使這一點非常清楚。

+0

我已經使用了6個td。我沒有發佈如果其他語句代碼在這裏。所以,只有你沒有看到剩下的3 td。我用另外3個td在if if語句中。我已更新我的代碼。再次查看 – Karuppiah

0

試試這個

<?php 
echo "<table width=1090 border=1 style=\"border: #ddd;\" align=center cellspacing=4 cellpadding=10>"; 
echo "<tr class=thvoucher>"; 
echo "<th width=30>Voucher Number</th>"; 
echo "<th width=80>Reference Number</th>"; 
echo "<th width=200>Guest Name</th>"; 
echo "<th width=150>Voucher Status</th>"; 
echo "<th width=150>Room Status</th>"; 
echo "<th width=150>Meal Status</th>"; 
echo "</tr>"; 
for($i = $start; $i < $end; $i++) 
{ 
    if ($i == $total_results) 
    { 
     break; 
    } 
    while($row = $stmt->fetch()) 
    { 
     $voucherid = $row['VoucherID']; 
     $ref = $row['VoucherReference']; 
     $gname = $row['GuestName']; 
     $vstatus = $row['ActiveStatus']; 
     echo "<tr class=voucherstyle" . $cls . ">"; 
     echo "<td>$voucherid</td>"; **// FIRST TD** 
     echo "<td>$ref</td>"; **// SECOND TD** 
     echo "<td>$gname</td>";  **// THIRD TD** 

     if($vstatus != 'empty')  **// FOURTH TD** 
     { 
      if($vstatus == 'Y') 
      { 
       echo "<td class=green >Active</td>"; 
      } 
      else if($vstatus == 'N') 
      { 
       echo "<td class=red >Inactive</td>"; 
      } 
     } 
     else 
     { 
      echo "<td><form method=post onsubmit=\"return mstatusvalidate(this)\"; action='voucherstatus_update.php?id_meal= $voucherid '><select name=mealstatus><option value=empty></option><option value=active>Active</option><option value=inactive>Inactive</option></select><input type=submit class=update_status title=\"Update $gname voucher status\" value=Update></form></td>"; 
     } 

     while($r_row = $r_stmt->fetch()) 
     { 
      $rstatus = $r_row['ActiveStatus']; 

      // same like above if else statement  **// FIFTH TD** 
     }  

     while($m_row = $m_stmt->fetch()) 
     { 
      $mstatus = $m_row['ActiveStatus']; 

        // same like above if else statement **// SIXTH TD**  
     } 
     echo "</tr>"; 
    } 
} 
echo "</table>"; 

?>

+0

我已更新我的代碼。請再次參閱 – Karuppiah

+0

編輯答案。嘗試一下。 第五和第六​​while循環需要在第一個while循環內。檢查上面的答案 – DixonMD

+0

我已經試過了。它不會工作。如果我喜歡這個房間和膳食狀態值(全部)顯示在第一行... – Karuppiah