PHP+mysql+jquery构建留言板加聊天室-留言展示

本项目所有代码都存储在github上有需要的可以去github上下载,希望大家给个 Satr
项目文章目录:
1、PHP+mysql+jquery构建留言板加聊天室-连接数据库
2、PHP+mysql+jquery构建留言板加聊天室-用户注册(带用户头像上传)
3、PHP+mysql+jquery构建留言板加聊天室-用户登录
4、PHP+mysql+jquery构建留言板加聊天室-留言展示
5、PHP+mysql+jquery构建留言板聊天室-留言的增、删、改功能
本文实现了留言板用户留言展示,能够展示用户头像、用户账号,留言时间和留言内容以及留言标题

show.php是留言板的主页面 其代码如下:

<?php
require_once('./conf.php');
?>
<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>留言显示</title>
    <link href="css/logindo.css" type="text/css" rel="stylesheet"> 
</head>
<body>
<div class="main">
    <h2>所有留言</h2>
    <a href="./add.php" style="float: right;">添加留言</a>
    &nbsp;&nbsp;
    <a href="./index1.php" style="float: right;">聊天室</a>
    <table class="table-integral">
        <thead>
            <tr>
                <td style="width:10%;">用户账户</td>
                <td style="width:10%;">用户头像</td>
                <td style="width:10%;">留言标题</td>
                <td style="width:10%;">留言内容</td>
                <td style="width:10%;">留言时间</td>
                <td style="width:10%;">操作</td>
            </tr>
        </thead>
        <tbody id="content_page">
            <?php
                $content = $mysql->select('select * from ly_content');#
                //$contents = $mysql->select("select headimg from ly_user where username=".$_SESSION['username']."");
                $i = 0;
                while (isset($content[$i])) {
                    ?>
                    <tr>
                    <td><?php echo $content[$i]['usernameid'] ?></td>
                    <td><?php echo '<img src="'.$content[$i]['headimg'].'" height="84px" width="70px" />' ?></td>    
                    <td><?php echo $content[$i]['title'] ?></td>
                    <td><?php echo $content[$i]['content'] ?></td>
                    <td><?php echo date('Y-m-d H:i:s', $content[$i]['time']) ?></td>
                    <td><a href="./up.php?  id=<?php echo $content[$i]['id'] ?>">编辑 | </a><a href="./del.php? id=<?php echo $content[$i]['id'] ?>">删除</a></td>
                    </tr>
                    <?php
                    $i++;
                }
            ?>
        </tbody>
    </table>
    <div id="wrap" class="page_btn clear"></div>
</div><!--main-->

<div id="info_modal" class="tips_info"></div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
    function Pagination($content, $wrap, options) {
        this.$wrap = $wrap;
        this.$content = $content;
        this.options = $.extend({}, Pagination.defaultOptions, options);
        this.init();
    }
    Pagination.defaultOptions = {
        size: 4
    };
    Pagination.prototype.init = function () {
        var totalItemNum = this.$content.children().length;
        var totalPageNum = this.totalPageNum = Math.ceil(totalItemNum / this.options.size);
        this.currentPage = 1;
        this.$wrap.empty();
        this.$content.children(':gt(' + (this.options.size - 1) + ')').hide();
        this.$wrap.append([
            '<span class="page_box">',
            '<a class="prev">上一页</a>',
            '<span class="num">',
            '</span>',
            '<a class="next">下一页</a>',
            '</span>'
        ].join(''));
        for (var i = 0; i < totalPageNum; i++) {
            var $btn = $('<span class="page-item">' + (i + 1) + '</span>');
            $btn.data('page', i + 1);
            this.$wrap.find('.num').append($btn);
        }
        this.$wrap.find('.num').children().eq(0).addClass('current');
        this.initEvents();
    };
    Pagination.prototype.initEvents = function () {
        var _this = this;
        var $prev = this.$wrap.find('.prev');
        var $next = this.$wrap.find('.next');
        var $num = this.$wrap.find('.num');

        $prev.on('click', function () {
            _this.prev();
        });
        $next.on('click', function () {
            _this.next();
        });
        $num.on('click', '.page-item', function () {
            var page = $(this).data('page');
            _this.goTo(page);
        });
    };
    Pagination.prototype.prev = function () {
        this.goTo(this.currentPage - 1);
    };
    Pagination.prototype.next = function () {
        this.goTo(this.currentPage + 1);
    };
    Pagination.prototype.goTo = function (num) {
        if (typeof num !== 'number') {
            throw new Error('e');
        }
        if(num > this.totalPageNum || num <= 0) {
            return false;
        }

        this.currentPage = num;

        this.$wrap.find('.num')
            .children().eq(this.currentPage - 1)
            .addClass('current').siblings('.current')
            .removeClass('current');

        var left = (this.currentPage - 1) * this.options.size;
        var right = left + this.options.size;

        var $shouldShow = this.$content.children().filter(function (index) {
            return left <= index && index < right;
        });
        this.$content.children().hide();
        $shouldShow.show();
    };

    var pagi = new Pagination($('#content_page'), $('#wrap'));


</script>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值