动态更改查询 - php,jquery

Hey I'm trying to get 2 main sql queries to be more dynamic.

When the user clicks the marketing link, I want the 2 queries below to be updated with that link Id:

1. <?php generate_pagination('SELECT * FROM explore WHERE category="marketing"'); ?>

so when the marketing link is clicked, I want the query to change the category in the query to whatever the link id or class is. In this case 'marketing'.

Here is the other query that needs to be updated dynamically with the same link click:

2. $sql = "SELECT * FROM explore WHERE category='marketing' ORDER BY category LIMIT $start,$per_page";

There are a total of three pages, posted below:

pagination.php

<?php
function generate_pagination($sql) {
  include_once('config.php');
  $per_page = 3;

  //Calculating no of pages
  $result = mysql_query($sql);
  $count = mysql_num_rows($result);
  $pages = ceil($count/$per_page);

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

<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>

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

<?php generate_pagination('SELECT * FROM explore WHERE category="marketing"'); ?>

<a href="#" id="marketing">Marketing</a>

</ul>
<br />
<br />

pagination_data.php:

<?php
include('config.php');
$per_page = 3;
if($_GET)
{
$page=$_GET['page'];
}

$start = ($page-1)*$per_page;
//$sql = "select * from explore order by id limit $start,$per_page";
$sql = "SELECT * FROM explore WHERE category='marketing' ORDER BY category LIMIT $start,$per_page";
$result = mysql_query($sql);
?>
<table width="800px">
<?php
while($row = mysql_fetch_array($result))
{
$msg_id=$row['id'];
$message=$row['site_description'];
$site_price=$row['site_price'];

?>
<tr>
<td><?php echo $msg_id; ?></td>
<td><?php echo $message; ?></td>
<td><?php echo $site_price; ?></td>
</tr>
<?php
}
?>
</table>

jquery_pagination.php:

$(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, function(){
          Hide_Load();
          $(this).attr('data-page', pageNum);
    });
});

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


        Display_Load();

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

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

                var pageNum = $('#content').attr('data-page');

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

});

1个回答



为简化起见,您应始终使用LIMIT和页面大小进行查询,即使偏移量为0。</ p>

<前> .. LIMIT 0,3
</ code> </ pre>

让另一个查询或缓存值计算记录(对于最大页码)。 Mysql的COUNT比num_row'ing SELECT *更好。</ p>

  $ start = intval($ _ GET ['page']);  //如果为null或false则为零
$ sql =“SELECT * FROM explore WHERE category ='marketing'ORDER BY category LIMIT $ start,$ per_page”;
</ code> </ pre>
</ div>

展开原文

原文

To simplify things, you should always query with a LIMIT and page size, even if the offset is 0.

.. LIMIT 0,3

Let another query or cached value count the records (for max page number) . Mysql's COUNT is better for this than num_row'ing SELECT *.

$start = intval($_GET['page']); // zero if null or false
$sql = "SELECT * FROM explore WHERE category='marketing' ORDER BY category LIMIT $start,$per_page";

duangangmo0583
duangangmo0583 这个类没有限制...或者说phpsense.com/php/php-pagination-script.html类页面
10 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐