PHP 循环 caps 数组并在表格行中显示每个项目

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

添加一个for循环,它将回显出所有字幕记录的内容 当您导航到本地主机中的 display_captions.php 脚本时的浏览器 目录路径。 php code我试图找出循环代码和回显。 完成的版本是什么样的[completed version]

php
1个回答
0
投票

试试这个


        <?

// Check connection
if (!$conn) {
    die("Connection failed:");
    } else {
// Proceed with your database operations here
        $cmd = "SELECT a.caption, b.img_loc
                FROM captions a
                INNER JOIN images b ON a.caption_id  b.caption_id
                 WHERE a.caption_id = b.caption_id " ;
// Added space after "images"
$result = mysqli_query($conn, $cmd);
// Fetch data and store in arrays

?>


<h2>Captions Table</h2>
<table>
   <thead>
      <tr>
       <th>Number</th>
      <th>Caption</th>
    </tr>
</thead>
<tbody>
    <?  $num=0;
        while ($row = mysqli_fetch_assoc($result)) {
    ?>

          <tr>
             <th><?=$num?></th>
             <th><?=$row['caption']?></th>
          </tr>

    <? $num ++ ;
      } ?>
</tbody>
</table>
© www.soinside.com 2019 - 2024. All rights reserved.