Php 如何在HTML表中添加与Mysql数据库中的条目数相等的行?

Php 如何在HTML表中添加与Mysql数据库中的条目数相等的行?,php,html,Php,Html,另外,如何访问每个值的? 这是我的HTML表格: <table class="inventory" style="float:left; position:relative;"> <tbody> <tr> <th>Name</th> <th>Rate</th> <th>OT</th> <th>Leaves&

另外,如何访问每个值的
? 这是我的HTML表格:

      <table class="inventory" style="float:left; position:relative;">
  <tbody>
    <tr>
      <th>Name</th>
      <th>Rate</th>
      <th>OT</th>
      <th>Leaves</th>
      <th>Total</th>
    </tr>
    <tr>
      <td>
          <input type="text" placeholder="Name"/>
      </td>
      <td>
      <input type="text" placeholder="Rate"/>
      </td>
      <td>
          <input type="text" placeholder="OT"/>
      </td>
      <td>
      <input type="text" placeholder="Leaves"/>
      </td>
      <td>
      <input type="text" placeholder="Total"/>
      </td>
    </tr>
    <tr>
        <td>
            <input type="text" placeholder="Name"/>
        </td>
        <td>
            <input type="text" placeholder="Rate"/>
        </td>
      <td>
      <input type="text" placeholder="OT"/>
      </td>
      <td>
      <input type="text" placeholder="Leaves"/>
      </td>
      <td>
      <input type="text" placeholder="Total"/>
      </td>
    </tr>
  </tbody>
        </table>

名称
比率
OT
叶子
全部的

如何在HTML表中添加与Mysql DB中的条目数相等的行?

您可以使用此编码并根据需要进行编辑

<table>
  <tr>
    <td>Name</td>
    <td>Rate</td>
    <td>OT</td>
    <td>Leaves</td>
    <td>Total</td>
  </tr>
  <?php

  $total_row=mysql_num_rows(mysql_query("SELECT * FROM  table_name"));
  $q="SELECT * FROM table_name";
  $run=mysql_query($q);
  if($total_row > 0)
  {
    while($row1=mysql_fetch_assoc($run))
    {

      $Name=$row1['Name'];
      $Rate=$row1['Rate'];
      $OT=$row1['OT'];
      $Leaves=$row1['Leaves'];
      $Total=$row1['Total'];
    ?>   
    </tr>
    <tr>
      <td><?php echo $Name;?></td>
      <td><?php echo $Rate;?></td>
      <td><?php echo $OT;?></td>
      <td><?php echo $Leaves;?></td>
      <td><?php echo $Total;?></td>
    </tr>
    <?php }
  }?>
</table>

名称
比率
OT
叶子
全部的

尝试以下方法:

$sql = "SELECT..."; //Add your query. Presumed you have 'name' column
$result = mysql_query($sql);

echo '<table class="inventory" style="float:left; position:relative;">';
echo '<thead>';
while ($row = mysql_fetch_assoc($result)) {
  echo '<tr>';
  echo '<th>'.$row["name"].'</th>';
  echo '</tr>';
}
echo '</thead>';
echo '<tbody>';
while ($row = mysql_fetch_assoc($result)) {
  echo '<tr>';
  echo '<td>';
  echo '<input type="text" placeholder="'.$row["name"].'"/>';
  echo '</td>';
  echo '</tr>';
}
echo '</tbody>';
echo '</table>';
$sql=“选择…”//添加您的查询。假设您有“名称”列
$result=mysql\u查询($sql);
回声';
回声';
while($row=mysql\u fetch\u assoc($result)){
回声';
回显'.$row[“name”].';
回声';
}
回声';
回声';
while($row=mysql\u fetch\u assoc($result)){
回声';
回声';
回声';
回声';
回声';
}
回声';
回声';

我假设您的数据库连接为
$con
。将数据库
表名
列名
放在适当的位置

<table class="inventory" style="float:left; position:relative;">
  <tbody>
    <tr>
      <th>Name</th>
      <th>Rate</th>
      <th>OT</th>
      <th>Leaves</th>
      <th>Total</th>
    </tr>
    <?php
    $query = mysqli_query($con,"SELECT * FROM tableName");
    while($row = mysqli_fetch_array($query,MYSQLI_ASSOC))
    {?>
    <tr>
      <td>
        <input type="text" placeholder="Name" value="<?php echo $row['Name_Column_name']?>"/>
      </td>
      <td>
        <input type="text" placeholder="Rate" value="<?php echo $row['Rate_Column_name']?>"/>
      </td>
      <td>
        <input type="text" placeholder="OT" value="<?php echo $row['OT_Column_name']?>"/>
      </td>
      <td>
        <input type="text" placeholder="Leaves" value="<?php echo $row['Leaves_Column_name']?>"/>
      </td>
      <td>
        <input type="text" placeholder="Total" value="<?php echo $row['Total_Column_name']?>"/>
      </td>
    </tr>
    <?php }?>
  </tbody>
</table>

名称
比率
OT
叶子
全部的

您必须运行查询。获取查询。我看不到您在哪里编写了任何sql查询。我看不到您从哪里获得
$\u SESSION['data']=$data
中的所有
样式
?我只是给出了我的项目中的代码,这就是为什么它包含这些样式的原因。。!!继续编码@VineetBasantani