猿问

错误的表格格式引导程序

我在 php 中的这段代码有问题,实际上在这个表中我想循环从数据库中获取的各种信息,只有当这些信息的长度不同时,每个表的格式都是错误的,我希望有相同的每条线的尺寸,就像我能做的那样?代码工作正常,格式错误......一列比另一列宽。我想用“N,名称,描述”这个词留下第一行,并用相同的大小循环其余部分。对不起英语


  while ($row = mysqli_fetch_array($r_query)) {

  echo '

  <table class="table table-bordered">

  <thead>

  <tr>

  <th scope="col">N°</th>

        <th scope="col">name</th>

        <th scope="col">description</th>

      </tr>

     </thead>

     <tbody>

      <tr>

        <th scope="row">' . $_id . '</th>

        <td>' . $_name . '</td>

        <td>' . $_description . '</td>

   <td>' . $_lingua . '</td>

   <td> <input class="btn btn-primary" type="submit" 

   value="Send"></td>

   </tr>

   </tbody>

   </table>';

   }


翻阅古今
浏览 167回答 1
1回答

潇湘沐

尝试将<table>部件和表头移到 PHP 循环之外,这样循环只会遍历每个数据项并添加一个新的表行,而不是为每条信息生成一个全新的表。echo '<table class="table table-bordered">&nbsp; &nbsp; &nbsp; &nbsp; <thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th scope="col">N°</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th scope="col">name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th scope="col">description</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; </thead>&nbsp; &nbsp; &nbsp; &nbsp; <tbody>';while ($row = mysqli_fetch_array($r_query)) {&nbsp; echo '<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th scope="row">' . $_id . '</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>' . $_name . '</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>' . $_description . '</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>' . $_lingua . '</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><input class="btn btn-primary" type="submit" value="Send"></td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>';}echo '</tbody>&nbsp; &nbsp; </table>';
随时随地看视频慕课网APP
我要回答