PHP + jQuery provides detailed explanation of the function of rolling screen without refreshing dynamic data loading, and jquery details

Source: Internet
Author: User
Tags echo date php database

PHP + jQuery provides detailed explanation of the function of rolling screen without refreshing dynamic data loading, and jquery details

This example describes how to use PHP + jQuery to dynamically load data without refreshing screen scrolling. We will share this with you for your reference. The details are as follows:

Index. php

<? Phprequire_once ('connect. php '); // connect to the database $ user = array ('demo1', 'demo2', 'demo3', 'demo3 ', '<de> </de> mo4'); // simulated users?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Ajax_demo. SQL

-- PhpMyAdmin SQL Dump -- version 3.5.2.2 -- http://www.phpmyadmin.net ---- HOST: localhost -- generation Date: January 18, 2015 -- server version: 5.1.46-community -- PHP version: 5.2.13SET SQL _MODE = "NO_AUTO_VALUE_ON_ZERO "; SET time_zone = "+ 00:00 ";/*! 40101 SET @ OLD_CHARACTER_SET_CLIENT = @ CHARACTER_SET_CLIENT */;/*! 40101 SET @ OLD_CHARACTER_SET_RESULTS = @ CHARACTER_SET_RESULTS */;/*! 40101 SET @ OLD_COLLATION_CONNECTION = @ COLLATION_CONNECTION */;/*! 40101 set names utf8 */; ---- Database: 'Demo' ---- ------------------------------------------------------------ TABLE structure 'types' -- create table if not exists' say '('id' int (11) not null AUTO_INCREMENT, 'userid' int (11) not null default '0', 'content' varchar (200) not null, 'addtime' int (10) not null, primary key ('id') ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 63; ---- data in the table to be retained 'say' -- insert into 'say '('Id', 'userid', 'content', 'addtime') VALUES (1, 0, 'Love love', 1421332482), (2, 1, 'Love love ', 1421332482), (3, 0, 'Love ai', 1421332482), (4, 1, 'Love ai', 1421332482), (5, 0, 'Love ai', 1421332482 ), (6, 0, 'love', 1421332482), (7, 0, 'love', 1421332482), (8, 2, 'love', 1421332482), (9, 0, 'Love ai', 1421332482), (10, 0, 'Love ai', 1421332482), (11, 0, 'Love ai', 1421332482), (12, 0, 'Love love', 1421332482), (13, 0, 'Love love', 1421332482), (14, 0, 'Love love' Ai', 1421332482), (15, 0, 'Love ai', 1421332482), (16, 0, 'Love ai', 1421332482), (17, 0, 'Love ai ', 1421332482), (18, 0, 'Love ai', 1421332482), (19, 0, 'Love ai', 1421332482), (20, 0, 'Love ai', 1421332482 ), (21, 0, 'love', 1421332482), (22, 0, 'love', 1421332482), (23, 0, 'love', 1421332482), (24, 0, 'Love ai', 1421332482), (25, 0, 'Love ai', 1421332482), (26, 0, '000000', 2222), (27, 0, '20140901', 2222), (28, 0, '20160901', 1421333159), (29, 0, '000000', 2222), (30, 0, '000000', 1421333162), (31, 0, '000000', 2222), (32, 0, '123', 2222), (33, 0, '123', 1421333167), (34, 0, '123', 2222), (35, 0, '123 ', 1421333170), (36, 0, '000000', 2222), (37, 0, '000000', 1421333172), (38, 0, '000000', 2222 ), (39, 0, '000000', 2222), (40, 0, '000000', 1421333176), (41, 0, '000000', 2222), (42, 0, '000000', 2222), (43, 0, '22 22 ', 1421333181), (44, 0, '000000', 2222), (45, 0, '000000', 1421333182), (46, 0, '000000 ', 1421333184), (47, 0, '000000', 2222), (48, 0, '000000', 1421333293), (49, 0, '000000', 2222 ), (50, 0, '000000', 2222), (51, 0, '000000', 1421333297), (52, 0, '000000', 2222), (53, 0, '000000', 2222), (54, 0, '000000', 1421333300), (55, 0, '000000', 2222), (56, 0, '123', 2222), (57, 0, '123', 1421333304 1333305), (58, 0, '000000', 2222), (59, 0, '000000', 1421333306), (60, 0, '000000', 2222 ), (61, 0, '000000', 2222), (62, 0, '000000', 1421333310 );/*! 40101 SET CHARACTER_SET_CLIENT = @ OLD_CHARACTER_SET_CLIENT */;/*! 40101 SET CHARACTER_SET_RESULTS = @ OLD_CHARACTER_SET_RESULTS */;/*! 40101 SET COLLATION_CONNECTION = @ OLD_COLLATION_CONNECTION */;

Result. php receiving request page

<? Phprequire_once ('connect. php '); // connect to the database $ user = array ('demo1', 'demo2', 'demo3', 'demo3', 'demo3 '); $ page = intval ($ _ GET ['page']); // GET the requested page number $ start = $ page * 15; $ query = mysqli_query ($ link, "select * from say order by id desc limit $ start, 15");/* while ($ row = mysqli_fetch_array ($ query )) {$ arr [] = array ('content' => $ row ['content'], 'author' => $ user [$ row ['userid'], 'date' => date ('m-d H: I ', $ row ['addtime']);} */ If ($ query) {while ($ row = mysqli_fetch_array ($ query) {$ arr [] = array ('content' => $ row ['content'], 'author' => $ user [$ row ['userid'], 'date' => date ('m-d H: I ', $ row ['addtime']) ;}} if (! Empty ($ arr) {echo json_encode ($ arr); // convert to json data output} // echo json_encode ($ arr); // convert to json data output?>

Connect. php Database Configuration File

<?php$host="localhost";$db_user="root";$db_pass="admin";$db_name="ajax_demo";$timezone="Asia/Shanghai";$link=mysqli_connect($host,$db_user,$db_pass);mysqli_select_db($link, $db_name);mysqli_query($link, "SET names UTF8");header("Content-Type: text/html; charset=utf-8");?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.