分页问题需要帮助

发布于 2024-08-21 15:39:11 字数 3253 浏览 5 评论 0原文

嘿,我正在尝试添加一个按钮,单击该按钮将从 mysql 数据库中获取数据并以分页方式显示它。但是,我似乎无法让它正常工作。

第一个主页如下所示: pagination.php:

<?php
include('config.php');
$per_page = 3;

//Calculating no of pages
$sql = "select * from explore";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page)
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>

<style>
body { margin: 0; padding: 5; font-family:Verdana; font-size:10px }
a
{
text-decoration:none;
color:#B2b2b2;

}

a:hover
{

color:#DF3D82;
text-decoration:underline;

}
#loading { 
width: 100%; 
position: absolute;
}

#pagination
{
text-align:center;
margin-left:120px;

}
li{ 
list-style: none; 
float: left; 
margin-right: 16px; 
padding:5px; 
border:solid 1px #dddddd;
color:#0063DC; 
}
li:hover
{ 
color:#FF0084; 
cursor: pointer; 
}
td{
border:solid 1px #dddddd;
padding:5px;
}


</style>



<div id="loading" ></div>
<div id="content" ></div>
<ul id="pagination">
<?php
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
?>

<p id="marketing">MARKETING</p>
</ul>
<br />
<br />

该页面上面的按钮如下所示:

<p id="marketing">MARKETING</p>

因此,当用户单击此按钮时,我需要它从数据库获取结果。

我用 jquery 这样做:

$(document).ready(function(){

    //Display Loading Image
    function Display_Load()
    {
        $("#loading").fadeIn(900,0);
        $("#loading").html("<img src='bigLoader.gif' />");
    }
    //Hide Loading Image
    function Hide_Load()
    {
        $("#loading").fadeOut('slow');
    };


   //Default Starting Page Results

    $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

    Display_Load();

    $("#content").load("pagination_data.php?page=1", Hide_Load());



    //Pagination Click
    $("#pagination li").click(function(){

        Display_Load();

        //CSS Styles
        $("#pagination li")
        .css({'border' : 'solid #dddddd 1px'})
        .css({'color' : '#0063DC'});

        $(this)
        .css({'color' : '#FF0084'})
        .css({'border' : 'none'});

        //Loading Data
        var pageNum = this.id;

        $("#content").load("pagination_data.php?page=" + pageNum, Hide_Load());

    });


// Editing below.        
        // Sort content Marketing    
        $("#pagination p").click(function () {


        Display_Load();

        //CSS Styles
        $("#pagination li")
        .css({'border' : 'solid #dddddd 1px'})
        .css({'color' : '#0063DC'});

        $(this)
        .css({'color' : '#FF0084'})
        .css({'border' : 'none'});

        //Loading Data
        var pageNum = this.id;

        $("#content").load("filter_marketing.php?page=" + pageNum, Hide_Load());
        });

});

问题是它不起作用,主要原因有一个: 1.页数=营销。我需要它是像上面的“pagination li”这样的数字。我不知道如何正确修复它。

如果我让您感到困惑,我会尝试更好地解释:

我想创建一个按钮(即营销),单击该按钮将从数据库获取数据并显示,但我还需要“刷新”分页号来补偿新数据。

如果您需要进一步的解释,请告诉我。任何帮助将不胜感激。谢谢。

Hey, I'm trying to add a button that when clicked will grab data from the mysql database and display it with a pagination. However, I can't seem to get it to work properly.

The first main page looks like this:
pagination.php:

<?php
include('config.php');
$per_page = 3;

//Calculating no of pages
$sql = "select * from explore";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page)
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>

<style>
body { margin: 0; padding: 5; font-family:Verdana; font-size:10px }
a
{
text-decoration:none;
color:#B2b2b2;

}

a:hover
{

color:#DF3D82;
text-decoration:underline;

}
#loading { 
width: 100%; 
position: absolute;
}

#pagination
{
text-align:center;
margin-left:120px;

}
li{ 
list-style: none; 
float: left; 
margin-right: 16px; 
padding:5px; 
border:solid 1px #dddddd;
color:#0063DC; 
}
li:hover
{ 
color:#FF0084; 
cursor: pointer; 
}
td{
border:solid 1px #dddddd;
padding:5px;
}


</style>



<div id="loading" ></div>
<div id="content" ></div>
<ul id="pagination">
<?php
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
?>

<p id="marketing">MARKETING</p>
</ul>
<br />
<br />

The button above in that page looks like this as you can see:

<p id="marketing">MARKETING</p>

So, when the user clicks this I need it to get the results from the db.

I do this with jquery like this:

$(document).ready(function(){

    //Display Loading Image
    function Display_Load()
    {
        $("#loading").fadeIn(900,0);
        $("#loading").html("<img src='bigLoader.gif' />");
    }
    //Hide Loading Image
    function Hide_Load()
    {
        $("#loading").fadeOut('slow');
    };


   //Default Starting Page Results

    $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

    Display_Load();

    $("#content").load("pagination_data.php?page=1", Hide_Load());



    //Pagination Click
    $("#pagination li").click(function(){

        Display_Load();

        //CSS Styles
        $("#pagination li")
        .css({'border' : 'solid #dddddd 1px'})
        .css({'color' : '#0063DC'});

        $(this)
        .css({'color' : '#FF0084'})
        .css({'border' : 'none'});

        //Loading Data
        var pageNum = this.id;

        $("#content").load("pagination_data.php?page=" + pageNum, Hide_Load());

    });


// Editing below.        
        // Sort content Marketing    
        $("#pagination p").click(function () {


        Display_Load();

        //CSS Styles
        $("#pagination li")
        .css({'border' : 'solid #dddddd 1px'})
        .css({'color' : '#0063DC'});

        $(this)
        .css({'color' : '#FF0084'})
        .css({'border' : 'none'});

        //Loading Data
        var pageNum = this.id;

        $("#content").load("filter_marketing.php?page=" + pageNum, Hide_Load());
        });

});

The problem is that does not work for one main reason:
1. PageNum = marketing. I need it to be the numbers like for 'pagination li' above. I do not know how to fix it properly.

In case I'm confusing you, I will try to explain better:

I want to create a button (i.e. Marketing) that when clicked will get the data from the database and display, but I also need the pagination numbers to be 'refreshed' to compensate for the new data.

If you need further explanation, please let me know. Any help would be greatly appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-08-28 15:39:11

认为您可能正在寻找 index()

 var pageNum = $(this).index() + 1;

请记住,索引是基于 0 的,因此添加 1。

这也取决于您的 html 标记,因为索引返回:

一个整数,指示 jQuery 对象中第一个元素相对于其同级元素的位置。

编辑:

因此,如果当您更新#content 的内容时,您还更改了数据页属性,那么当您单击#marketing 时,您也可以获得该信息,这样您就知道要获取哪个页面。

如果您要为其中一个 LI 元素指定一个“当前页”类,然后获取 .current-class LI 的 id,这也将起作用。

<div id="content" data-page="1"></div>

杰斯:

//Pagination Click
$("#pagination li").click(function(){
    //...
    $("#content").load("pagination_data.php?page=" + pageNum, function(){
          Hide_Load();
          $(this).attr('data-page', pageNum);
    });
});


$("#pagination p").click(function () {
    //...
    var pageNum = $('#content').attr('data-page');

    $("#content").load("filter_marketing.php?page=" + pageNum, Hide_Load());
 });

Think you might be looking for index().

 var pageNum = $(this).index() + 1;

Keep in mind that index is 0 based, hence the add 1.

This would also be dependent on your html markup because index returns:

an integer indicating the position of the first element within the jQuery object relative to its sibling elements.

EDIT:

So if, when you update the content of #content, you also change the data-page attribute, you can also have that information when you click on #marketing, so you know which page to get.

This would also work if you were to give one of the LI elements a "current-page" class and then get the id of the .current-class LI.

<div id="content" data-page="1"></div>

Js:

//Pagination Click
$("#pagination li").click(function(){
    //...
    $("#content").load("pagination_data.php?page=" + pageNum, function(){
          Hide_Load();
          $(this).attr('data-page', pageNum);
    });
});


$("#pagination p").click(function () {
    //...
    var pageNum = $('#content').attr('data-page');

    $("#content").load("filter_marketing.php?page=" + pageNum, Hide_Load());
 });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文