使用php显示数据表的问题

问题描述 投票:0回答:1

我的显示数据从PHP转换为HTML表时遇到问题我收到正确的数据,但我知道如何不为每个结果获取collums名称我的代码PHP:

$statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $total_row = $statement->rowCount();
    $output = '';
    if($total_row > 0)
    {
        foreach($result as $row)
        {
            $output .= '
<table class="table">
 <thead>
    <tr>
      <th scope="col">ID</th>
      <th scope="col">Region</th>
      <th scope="col">Level</th>
      <th scope="col">Status</th>
      <th scope="col">BE</th>
      <th scope="col">RP</th>
      <th scope="col">Current Rank</th>
      <th scope="col">Previous Rank</th>
      <th scope="col">Flex Rank</th>
      <th scope="col">Champions Count</th>
      <th scope="col">Skin Count</th>
     <th scope="col">Last Play</th>
     <th scope="col">Price</th>
    </tr>
 </thead>
</tr>
<td>'.$row["id"].'</td>
<td>'.$row["region"].'</td>
<td>'.$row["level"].'</td>
<td>'.$row["account_status"].'</td>
<td>'.$row["be"].'</td>
<td>'.$row["rp"].'</td>
<td>'.$row["current_rank"].'</td>
<td>'.$row["previous_rank"].'</td>
<td>'.$row["flex_rank"].'</td>
<td>'.$row["champions_count"].'</td>
<td>'.$row["skins_count"].'</td>
<td>'.$row["last_play"].'</td>
<td>'.$row["price"].'</td>
 ';

        }
    }
    else
    {
        $output = '<h3>No Data Found</h3>';
    }
    echo $output;

HTML:


        <div class="col-md-9">
            <div class="row filter_data">


            </div>
        </div>

filter_data来自Ajax。

[https://prnt.sc/rd4t3f-结果

我想只在表中接收来自collum的信息,而不是每个时间collum名称

php html html-table
1个回答
0
投票

仅对行进行迭代

 $statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $total_row = $statement->rowCount();
    $output = '';
    if($total_row > 0)
    {

    $output .= '
        <table class="table">
         <thead>
            <tr>
              <th scope="col">ID</th>
              <th scope="col">Region</th>
              <th scope="col">Level</th>
              <th scope="col">Status</th>
              <th scope="col">BE</th>
              <th scope="col">RP</th>
              <th scope="col">Current Rank</th>
              <th scope="col">Previous Rank</th>
              <th scope="col">Flex Rank</th>
              <th scope="col">Champions Count</th>
              <th scope="col">Skin Count</th>
             <th scope="col">Last Play</th>
             <th scope="col">Price</th>
            </tr>
         </thead>
        '

        foreach($result as $row)
        {
           $output .= ' <tr>
           <td>'.$row["id"].'</td>
           <td>'.$row["region"].'</td>
           <td>'.$row["level"].'</td>
           <td>'.$row["account_status"].'</td>
           <td>'.$row["be"].'</td>
           <td>'.$row["rp"].'</td>
           <td>'.$row["current_rank"].'</td>
           <td>'.$row["previous_rank"].'</td>
           <td>'.$row["flex_rank"].'</td>
           <td>'.$row["champions_count"].'</td>
           <td>'.$row["skins_count"].'</td>
           <td>'.$row["last_play"].'</td>
           <td>'.$row["price"].'</td>
          </tr>
          ';

         }

     $output .= ' </table>'
}
else
{
    $output = '<h3>No Data Found</h3>';
}
echo $output;
© www.soinside.com 2019 - 2024. All rights reserved.