Home  >  Article  >  Backend Development  >  php+jQuery implements news tag classification and refresh-free paging_PHP tutorial

php+jQuery implements news tag classification and refresh-free paging_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:04852browse

Nowadays, jquery is used more and more widely, and the effect of tag classification + non-refresh paging has been implemented in the news section of many websites.

I also tried to write one myself, and the rendering is as follows (the style can be customized according to user needs):

The implementation process will be introduced in detail below:

I have always tried to solve the problem by seeing the tricks. Three things need to be used here - tab effect plug-in and paging plug-in, and jquery's getJson request.

So I used the jquery-ui plug-in and jquery-page plug-in. Please click on the file name below to download.

It contains 3 JS script files and 2 style sheets:

jquery-1.3.2.min.js

jquery.pager.js

jquery-ui-1.7.2.custom.min.js

jquery-ui-1.7.2.custom.css

page.css

The html page code is as follows:

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.bkjia.com]


php + jquery ui + jquery pager - Liehuo.Net














The page makes getJson requests for three pages: ajax4.php, ajax5.php, and ajax6.php.

The codes of these three pages are similar. They are just the classification of years. I have not done the code here. It has been optimized.

can actually be processed on the same page. Just add a parameter to the request address.

Ajax.php code is as follows:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]
header("content-type:text/html;charset:utf-8");
$db = @ mysql_connect("Server host address", "Database account"," Database password");
mysql_select_db("database name");
$rs=mysql_query("set names utf8");
//If the pager parameter is passed
if(isset($_GET ['pager']) && isset($_GET['count']))
{
echo GetPager($_GET['count'],$_GET['pager']);
}
else
{
echo "No parameters passed in!";
}


function GetPager($count,$pager)
{

$begin = start time;
$end = end time;

$rs=mysql_query("SELECT * FROM data table WHERE (pubdate BETWEEN $begin AND $end) ORDER BY pubdate DESC limit ". ($pager-1)*$count.",".$count);

while ($r=mysql_fetch_assoc($rs))
{
$temp[]=$r;
}

$html_string="";
foreach($temp as $k=>$v)
{
//Assume that the url field is the link address, title is the news title, and pubdate is the publication time

$html_string.=" ";
}


$html_string.="
 * ".$v['title']. "".$v["pubdate"]."
";
//This is the number of news reads, it is not recommended to read too much
$num=40 ;
//The total number of news pages is rounded
$num_string=ceil($num/$count);

//The data in JSON format is returned here in the form of key-value pairs, 0 is the total number of news pages, 1 is the spliced ​​HTML news page
$arr=array("0"=>$num_string, "1"=>$html_string);
$jarr=json_encode($arr );
echo $jarr;

}

?>

Reprinted from: http://www.cnblogs.com/tianxin2001x/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364463.htmlTechArticleNow jquery is more and more widely used, and tag classification + no refresh has been implemented in the news section of many websites Pagination effect. I also tried to write one myself, and the effect is as follows (like...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn