jquery+ajax+mysql+php上拉加载或者jquery+ajax+mysql+php滚动条向下滚动加载

本文介绍了如何结合jQuery、Ajax、MySQL和PHP来实现在网页中进行上拉加载或滚动条向下滚动时动态加载更多数据。通过connect.php建立数据库连接,pages.php处理请求并获取数据,index.html展示内容,并且提供了food.sql用于创建数据库表。这个方案可以有效提高用户体验,避免一次性加载大量数据。
摘要由CSDN通过智能技术生成
connect.php

<?php
$host="localhost";
$db_user="root";
$db_pass="root";
$db_name="food";
$timezone="Asia/Shanghai";

$link=mysql_connect($host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
mysql_query("SET names UTF8");

header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set($timezone); //北京时间
?>

pages.php

<?php
include_once('connect.php');

$page = intval($_POST['pageNum']);

$result = mysql_query("select id from food");
$total = mysql_num_rows($result);//总记录数

$pageSize = 6; //每页显示数
$totalPage = ceil($total/$pageSize); //总页数

$startPage = $page*$pageSize;
$arr['total'] = $total;
$arr['pageSize'] = $pageSize;
$arr['totalPage'] = $totalPage;
$query = mysql_query("select id,title,pic from food order by id asc limit $startPage,$pageSize");
while($row=mysql_fetch_array($query)){
	 $arr['list'][] = array(
	 	'id' => $row['id'],
		'title' => $row['title'],
		'pic' => $row['pic'],
	 );
}
//print_r($arr);
echo json_encode($arr);
?>

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="ajax分页,jquery,php" />
<meta name="description" content="jquery+ajax+msql+php上拉加载或者jquery+ajax+msql+php滚动条向下滚动加载" />
<title>jquery+ajax+msql+php上拉加载或者jquery+ajax+msql+php滚动条向下滚动加载</title>

<style type="text/css">


body{
	width:1349px;
	height:auto;
	margin:0;
	padding:0;
}

#main{
	width:980px;
	margin:0 auto;
	height:auto;
	text-align:center
	
}

.nodata{
	w
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值