donglie1994 2016-01-12 17:15
浏览 34
已采纳

在表中显示SQL数据

A few months ago, I made a system where people could upload a picture and then those pictures would be displayed in a table with 4 columns. Now I am working on a project (to practice my php, I am still learning it) and I would like to use a similar system as below but it should display data from a database. The result I was trying to achieve is the data being displayed in 2 columns.

if ($handle = opendir('images/')) {
    $bool = true;
    while ($bool) {
       $td = 1;
       echo '<tr>';
       while ($td < 4) {
          $file = readdir($handle);
          if ($file != '.' && $file != '..' && $file != '.DS_Store') {
             echo '<td>';
             if ($file) {
                echo '<img src="images/'.$file.
                '">';
             } else {
                $bool = false;
             }
             echo '</td>';
             $td++;
          }
       }
       echo '</tr>';
    }
 }
 closedir($handle);
  • 写回答

1条回答 默认 最新

  • dsebywql016137 2016-01-12 18:18
    关注

    For anyone looking for the answer:

     $query = "SELECT * FROM webshop";
                    if($query_run = mysql_query($query)) {
                        $bool = true;
                        echo '<table>';
                        while($bool) {
                            $td = 0;
                            echo '<tr>';
                            while($td < 2) {
                                if($fetch = mysql_fetch_assoc($query_run)) {
                                    echo '<td>';
                                    $title = $fetch['title'];
                                    $info = $fetch['info'];
                                    /* Commented out for now, will be implemented later
                                    $image = $fetch['image'];
                                    $price = $fetch['price'];
                                    */
                                    echo $title;
                                } else {
                                    $bool = false;
                                }
                                echo '</td>';
                                $td++;
                            }
                            echo '</tr>';
                        }
                        echo '</table>';
                    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器