簡體   English   中英

如何在表格中顯示所有值

[英]How to display all the values in the table

我在下面的代碼中遇到了job_table的問題。 我希望表顯示它們已插入表中的所有作業。 而是只顯示最新的。 顯示這些值的值為$ ee($ start和$ end為開始和結束日期)。 再次出現的問題是,它不會僅顯示最后一個作業就顯示所有作業。 有誰知道如何解決這個問題? 與數組有關嗎? 提前致謝

  $employment_table = "no table";
  $sql = "SELECT * FROM history WHERE userID='$profile_id' AND type='job'";
  $query = mysqli_query($db_conx, $sql) or die(mysqli_error($db_conx));

   while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
     $h_id = $row["id"];
     $ee = $row["ee"];
     $htype = $row["type"];
     $unixstart = $row["start"];
     $unixend = $row["end"];
       $start = date("d/m/Y",$unixstart);
       $end =  date("d/m/Y",$unixend);
  $employment_table = "<table>";
  $employment_table .= "<tr>";
  $employment_table .= "<th>Company Name</td>";
  $employment_table .= " <th>Start Date</td>";
  $employment_table .= "<th>End Date</td>";
  $employment_table .= "</tr>";
  $employment_table .= "<tr>";
  $employment_table .= "<td>".$ee."</td>";
  $employment_table .= "<td>".$start."</td>";
  $employment_table .= "<td>".$end."</td>";
  $employment_table .= "</tr>";
  $employment_table .= "</table>";      
 }

您每次在循環中都會覆蓋$employment_table變量。 <table></table>標記移出循環-例如

    $employment_table = "<table>";
    while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
         $h_id = $row["id"];
         $ee = $row["ee"];
         $htype = $row["type"];
         $unixstart = $row["start"];
         $unixend = $row["end"];
           $start = date("d/m/Y",$unixstart);
           $end =  date("d/m/Y",$unixend);

      $employment_table .= "<tr>";
      $employment_table .= "<th>Company Name</td>";
      $employment_table .= " <th>Start Date</td>";
      $employment_table .= "<th>End Date</td>";
      $employment_table .= "</tr>";
      $employment_table .= "<tr>";
      $employment_table .= "<td>".$ee."</td>";
      $employment_table .= "<td>".$start."</td>";
      $employment_table .= "<td>".$end."</td>";
      $employment_table .= "</tr>";

     }
$employment_table .= "</table>";

您每次迭代都會覆蓋$employment_table 您還為每行創建一個新表。

因此,請執行以下操作:

$employment_table = "<table>";
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
    $h_id = $row["id"];
    $ee = $row["ee"];
    $htype = $row["type"];
    $unixstart = $row["start"];
    $unixend = $row["end"];
    $start = date("d/m/Y",$unixstart);
    $end =  date("d/m/Y",$unixend);
    $employment_table .= "<tr>";
    $employment_table .= "<th>Company Name</td>";
    $employment_table .= " <th>Start Date</td>";
    $employment_table .= "<th>End Date</td>";
    $employment_table .= "</tr>";
    $employment_table .= "<tr>";
    $employment_table .= "<td>".$ee."</td>";
    $employment_table .= "<td>".$start."</td>";
    $employment_table .= "<td>".$end."</td>";
    $employment_table .= "</tr>";
}
$employment_table .= "</table>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM