javascript - 从数据库中获取的 html 图像图库 View

标签 javascript php jquery html

我的列表中有近 200 张图像。

$rings = $db->query("SELECT * FROM rings WHERE id > ". $ringId ." LIMIT 100"); 

我想以图库表单的形式显示它们,每个表单都有一个复选框。每行必须包含至少 4 个带有复选框的图像。

我尝试过,通过添加 div 来创建 for 循环,但每次只能在 Ring 上垂直添加。我怎样才能给它某种画廊的外观。

<div>

                                    <?php
                                            echo "<table><tr>";
                                            $i =0;
                                            foreach( $rings as $ring )
                                            {
                                               $i++;
                                               echo '<td><input type="image" src="http://thevowapp.com/iphoneapp/vowstore/rings/'.  $ring['imagePath'] .'" name="checked" value="' . $ring['id'].'" data-my-info="'. $ring['ringSetName'] .'" style="width:280px; height:280px;"></td>';
                                               echo '<input type="checkbox">';
                                               if( $i % 3 == 0 )
                                               {
                                                 echo "</tr><tr>";
                                               }
                                             }
                                             echo "</tr></table>";
                                       ?>
                               </div>

最佳答案

您需要控制输出,使其水平输出,直到该行中有 4 个图像,然后开始一个新行。

另外,我可以为此建议一个表结构吗?

echo "<table>
       <tr>";
$i=0;
foreach( $rings as $ring ):
  $i++
  echo "<td><img src='{$ring['thumb']}' /></td>";
  if( $i % 4 == 0 ){
    echo "</tr><tr>";
  }
}
echo "</tr></table>";

关于javascript - 从数据库中获取的 html 图像图库 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632316/

相关文章:

javascript - 使用 Math.PI 降低曲线速度

php - 重定向到非 https 页面

javascript - 在同一页面登录,检查SESSION,无需重新加载

javascript - react native 卡( native 基础)onPress 不起作用

javascript - 在reactjs中使用superagent删除

javascript - 错误 : valLists is undefined in pagination of table rows using AngularJS, AJAX

php - mysqli查询结果显示所有行

jquery - 无法为标签元素设置边距

javascript - Backbonejs 替换 $el

javascript - Greasemonkey 是否允许通过@require 加载本地javascript?