在多列中显示动态数据

时间:2018-05-18 01:27:11

标签: sql layout dynamic

我在php中使用html字符串在单个列中显示sql查询结果: single

如何使用多列来进行布局: enter image description here

while($row = mysqli_fetch_array($q)){
                $id = $row['id'];
                $title = $row['title'];
                $desc = $row['description'];
                $link = $row['link'];

                $output .= '<a href="' . $link . '">
                            <h3>' . $title . '</h3>
                                <p>' . $desc . '</p>
                            </a>';
            }

1 个答案:

答案 0 :(得分:0)

感谢hungrykoala获取有关此问题的帮助

            $i = 0 ;
            $resultsPerRow = 2 ;
            $output = '<tr>';
            while($row = mysqli_fetch_array($q)){
                $i++;
                $id = $row['id'];
                $title = $row['title'];
                $desc = $row['description'];
                $link = $row['link'];
                $output .= '<td><a href="' .$link. '">' .$title. '<br>' .$desc. '</a></td>';    

                if ($i % $resultsPerRow == 0) {     
                $output .= '</tr><td><br></td><tr>'; 
                }                   
            }
        echo($output);

然后输出到表格标签