从Mysql数据库c#旋转Blockquote

本文关键字:旋转 Blockquote 数据库 Mysql | 更新日期: 2023-09-27 17:49:24

我的DB

CREATE TABLE IF NOT EXISTS `comments` (
  `com_id` int(11) NOT NULL AUTO_INCREMENT,
  `com_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `com_content` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `com_website` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `com_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`com_id`)
)

这是我的前端

<link href="js/jquery.bxslider.css" rel="stylesheet" type="text/css" />
 <div class="container">
    <asp:Label ID="lblComment" runat="server" Text=""/>
</div>
<script src="js/jquery.bxslider.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.bxslider').bxSlider({
            mode: 'horizontal',
            slideMargin: 3,
            auto: true
        });
    });
</script>

最后这是我的后端

private void dispComments()
{
    using (MySqlConnection conn = new MySqlConnection("server=localhost;database=test;uid=root;password="))
    {
        string query = "select * from comments order by com_date desc";
        DataTable dt = new DataTable();
        using (MySqlDataAdapter da = new MySqlDataAdapter(query, conn))
        {
            da.Fill(dt);
            string comment = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //Message title
                //news += "<div class='page-header' style='text-transform:capitalize;'><small>";
                //news += dt.Rows[i]["com_content"].ToString();
                //news +="</small></div>";
                //Message Body
                comment += "<ul class='bxslider'>";
                comment += "<li>";
                comment += "<blockquote>";
                comment += dt.Rows[i]["com_content"].ToString();
                comment += "<p style='text-align: right; margin-right: 20px;'>";
                comment += dt.Rows[i]["com_name"].ToString();
                comment += "</p></blockquote>";
                comment += "</li>";
                comment += "</ul>";
            }
            lblComment.Text = comment;
        }
    }
}

…我的评论表上有3条评论,所有这三个都显示出来,输出很好,除了它们倾向于单独出现,每次旋转只显示一条评论。我哪里出错了?请帮助! !

从Mysql数据库c#旋转Blockquote

<ul>应在for环外。当前代码在每次迭代下都会创建一个新的<ul>。因此,对于每个li,您都有一个ul,对于每个ul,滑动条被初始化。

修改为以下代码

string comment = null;
comment += "<ul class='bxslider'>";
for (int i = 0; i < dt.Rows.Count; i++)
{
    comment += "<li>";
    ....
    comment += "</li>";
}
comment += "</ul>";