mysqli/PHP-前两行永远不会出现(表中的行数据穿过列,然后向下移动)


mysqli/PHP - first two rows never show up(table with row data going across columns then moving down)

我的网站当前忽略您放入数据库的前两个图像,然后继续添加跨越5列的图像,然后向下移动到下一行。

更新:现在它显示了数据库中4个图像中的3个。跳过一个图像。

<?php
$i = 1; 
echo "<table>"; 
while ($row = $Recordset2->fetch_object()) { 
  if ($i == 1) { 
     echo "<tr>"; 
  } 
  echo '<td><img src="'.$row_Recordset2['ImgSource'].'" width="100" height="100"></td>'; 
  if ($i == 5) { 
     $i = 1; 
     echo "</tr>"; 
  } else { 
     $i++; 
  } 
} 
echo "</table>";   
?>

这就是我的数据库的样子https://i.stack.imgur.com/IFba8.jpg

这是我的网站显示的内容https://i.stack.imgur.com/Wf7E1.jpg

试试这个:

<?php
$i = 1;  
echo "<table>"; 
while ($row = $Recordset2->fetch_object()) { 
  if ($i == 1) { 
     echo "<tr>"; 
  } 
  echo '<td><img src="'.$row['ImgSource'].'" width="100" height="100"></td>'; 
  if ($i == 5) { 
     $i = 1; 
     echo "</tr>"; 
  } else { 
     $i++; 
  } 
} 
echo "</table>";   
?>

请尝试一下。

   <?php
    $i = 1;  
    echo "<table>"; 
    while ( $row = $Recordset2->fetch_object() ) { 
      if ($i == 1) { 
         echo "<tr>"; 
      } 
      echo '<td><img src="'.$row_Recordset2['ImgSource'].'" width="100" height="100"></td>'; 
      if ($i == 5) { 
         $i = 1; 
         echo "</tr>"; 
      } else { 
         $i++; 
      } 
    } 
    echo "</table>"; 
?>