来自数据库的MySQL数据水平对齐 [英] MySQL data from database align horizontally

查看:336
本文介绍了来自数据库的MySQL数据水平对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基本的网站,将显示10个不同的电视节目。
我有10个不同的程序存储在数据库中。我能够检索10个程序,但它们都出现在一列中。
我想知道是否有一种方法可以连续出现5次?
我已经尝试了基本的CSS,但我似乎无法得到它的工作

Im creating a basic website that will show 10 different tv programmes. I have the 10 different programmes stored in the database. Im able to retriev the 10 programmes but they all appear in a column. I was wondering if theres a way to have then appear 5 in a row? I have tried basic CSS but i cant seem to get it working

以下是我到目前为止的代码:

Here is the code i have so far:

<?php
$results = $mysqli->query("SELECT * FROM programmes ORDER BY ProgrammeName ASC");
if ($results) { 
     while($obj = $results->fetch_object())
    {
        echo '<br>';
        echo '<div class="tvProgs">'; 
        echo '<form method="post" id = "books" action="cart_update.php">';
        echo '<div class="progImage"><img src="images/'.$obj->Image.'"></div>';
        echo '<div class="progTitle"><h3>'.$obj->ProgrammeName.'</h3>';
        echo '</form>';
        echo '</div>';
    }
}
?>

我想知道是否有一种方法可以实现我想要的或者我将不得不尝试其他方法?

I was wondering if theres a way to achive that i want or will i have to try something else?

任何东西都会有帮助。

谢谢!

Thanks!

推荐答案

尝试将它们放在表格中:

Try to put them in a table:

<?php
$results = $mysqli->query("SELECT * FROM programmes ORDER BY ProgrammeName ASC");
if ($results) { 
     $i=0;
     echo '<table><tr>';
     while($obj = $results->fetch_object())
    {
        echo '<td>';
        echo '<div class="tvProgs">'; 
        echo '<form method="post" id = "books" action="cart_update.php">';
        echo '<div class="progImage"><img src="images/'.$obj->Image.'"></div>';
        echo '<div class="progTitle"><h3>'.$obj->ProgrammeName.'</h3>';
        echo '</form>';
        echo '</div>';
        echo '</td>';
        $i++; 
        if ($i == 5) {
          echo '</tr><tr>';
        }
    }
     echo '</tr></table>';
}
?>

这篇关于来自数据库的MySQL数据水平对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆