dongzhan1570 2018-09-07 17:06
浏览 43

如何使用while循环在同一个表中插入新行

I'm trying to make 3 tables, I've used this while loop, the problem that I didn't know how to make the loop insert the new row in the same table. It makes new tables for each new row or just mess it up by putting information that should appear in another table.

Please help me.

What I got:

contract    name    cost    period
 210         sama     20        3


id         date    account    visit
2         3-jun      20        3
...
contract    name    cost    period
200         mama     10        3

id         date    account    visit
4          10        3         2

....
contract    name    cost    period
210         ana      50        6

id         date    account    visit
6          50        6         5

What I want:

contract    name    cost    period
210         sama     20        3
200         mama     10        3
210         ana      50        6


id         date    account    visit
2         3-jun      20        3
4          10        3         2
6          50        6         5

This is my code:

<?php while($row = mysqli_fetch_array($search_result)):?>

 <div style="font-size:1.5rem;  padding:0px; margin:0px; position:relative; width:95%; " dir="rtl">
      <h1>contract </h1>
 <table bgcolor="#fff" align="center" width="70%" border="3" dir="rtl" style="font-size:1.5rem; ">
 <tr>

  <td>name</td>
  <td>cost</td>
     <td>period</td>



  <tr>

  <td><?php echo $row['contract_num'];?></td>   
  <td><?php echo $row['cost'];?></td>
   <td><?php echo $row['bla'];?></td>
  <td><?php echo $row['serv'];?></td>


   </tr>
   </table></div>


 <div style="font-size:1.5rem;  padding:0px; margin:0px; position:relative; width:95%; " dir="rtl">
  <h1>visits</h1>
 <table bgcolor="#fff" align="center" width="70%" border="3" dir="rtl" style="font-size:1.5rem;  ">
 <tr>
  <td>id</td>    

     <td>date</td>    
  <td>account</td>  
     <td>visit</td>

     <tr>

  <td><?php echo $row['id'];?></td>

      <td><?php echo $row['date'];?></td>  
          <td><?php echo $row['account'];?></td>

      <td><?php echo $row['visit'];?></td>  
     </tr>
     </table></div>


     <?php endwhile;?>
  • 写回答

1条回答 默认 最新

  • doudizhu2222 2018-09-07 17:13
    关注

    Read more on tables: https://www.w3schools.com/html/html_tables.asp

    thead - define table header. It has one row (tr) with your table's headers (th)

    tbody - set the data for the columns. tr = table row, td = table data, or table cell

    <table>
        <thead> <!-- define the header outside the while, it only needs to be defined once -->
            <tr>
                <th>Contract</th>
                <th>Name</th>
                <th>Cost</th>
                <th>Period</th>
            </tr>
        </thead>
        <tbody> <!-- in the body loop through all results and print one row for each result -->
            <?php while($row...): ?>
                <tr>
                    <td><?php echo $row['contract'] ?></td>
                    <td><?php echo $row['name'] ?></td>
                    <td><?php echo $row['cost'] ?></td>
                    <td><?php echo $row['period'] ?></td>
                </tr>
            <?php endwhile; ?>
        </tbody>
    </table>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line