
正文
php无刷新数据库 php无刷新分页
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求一个PHP + Ajax 表单无刷新大批量修改数据的实例
!DOCTYPE HTML
html
head
title微吧外卖/title
meta name="keywords"
content="JqueryMobile JqueryMobile进阶 JqueryMobile教程 Jquery mobile进阶 转屏效果php无刷新数据库的简单实现 Warren " /
meta name="description" content="模拟JqueryMobile slide转屏效果php无刷新数据库的简单实现" /
meta http-equiv="Content-Type" content="text/html; charset=utf-8"
meta name="viewport"
content="user-scalable=no, width=device-width, initial-scale=1.0" /
meta name="apple-mobile-web-app-capable" content="yes"
meta name="apple-mobile-web-app-status-bar-style" content="black"
link rel="stylesheet" href="css/user_home.css"/
script src="js/jquery-1.9.1.min.js"/script
style
#scroller3{margin-top:2em;
margin-left: 1.3em;
font-size: 2em;
}
#scroller3 input{height: 3em;
width: 80%;
margin-top: 1.5em;
margin-left: 2em;
border-top: none;
border-left: none;
border-right: none;
border-bottom: 1px solid #ef7b14;}
#pwd{margin-top:2em;}
#btn{display: block;
font-weight: bold;
height: 3.6em;
border: none;
color: #fff;
background: #ef7b14;
margin-top: 2em;
border-radius: 0.3em;
}
.da{border: 1px solid #ef7b14;
width: 90%;
height: 9em;
border-radius: 0.3em;
}
.da span{padding-left:0.5em; }
/style
/head
body
div id="page4" class="ui-mobile-viewport-transitioning ui-page hide"
div class="header"
h1商家手机号登录/h1
/div
h2 style="font-size: 3em;color: #ef7b14;margin: 1em"微吧欢迎您 :)/h2
div id="scroller3"
form id="loginForm"
div class="da"
input type="text" value="" id="pwd" name="shop" placeholder="店铺名称"/br/
input type="text" value="" name="name" id="name" placeholder="用户名"/br/
input type="password" value="" id="pwd" name="pwd" placeholder="密码"/br/
/div
input type="button" id="btn" value="登录"/
/form
/div
/div
script
$('#btn').click(function(){
var str=$('#loginForm').serialize();
// alert(str);
$.ajax({
url:'',
dataType: "jsonp",
jsonpCallback: "callback",
type:'post',
data:str,
success:function(data){
if(data.status=='ok'){
alert(data.msg);
location.href="./home.html"
}else{
alert(data.msg);
}
},
error:function(error){
alert(error);
}
})
})
/script
/body
/html
?php
header('content-type:text/html;charset=utf-8');
$con=mysql_connect('连接数据库');
$dd=mysql_select_db('连接数据库名字');
mysql_query('set names utf8');
session_start();
$phone=$_GET["name"];
$pwd=$_GET["pwd"];
$shop=$_GET["shop"];
$selectSqlStr=mysql_query("select * from shopuser where shop='".$shop."'and tel='".$phone."' and pwd='".$pwd."'");
$row= mysql_num_rows($selectSqlStr);
$str= mysql_fetch_assoc($selectSqlStr);
if($row0){
setcookie("tel",$phone,time()+24*3600);
echo 'callback({"status":"ok","msg":"登录成功","str":"'.$row.'"})';
}else{
echo 'callback({"status":"no","msg":"用户名与密码不符?","str":"'.$row.'"})';
echo $_SESSION["tel"];
}
mysql_close($con);
?
相关问答
Q1: php怎么实现无刷新分页效果
php+ajax实现无刷新分页实现方法具体如下:
limit 偏移量,长度;
limit 0,7; 第一页
limit 7,7; 第二页
limit 14,7; 第三页
每页信息条数:7
信息总条数:select count(*) from table
信息总页数:ceil向上取整(总条数/每页条数)
1、分页类具体使用
?php
class Pagination {
private $total; //数据表中总记录数
private $listRows; //每页显示行数
private $limit; //mysql 数据库的limit
private $uri; //分页信息前面的uri地址
private $pageNum; //页数
private $config = array('header' = "个记录", "prev" = "【上一页】", "next" = "【下一页】", "first" = "【首 页】", "last" = "【尾 页】");
private $listNum = 8;
/*
* $total 当前信息总条数
* $listRows 每页显示的条数
* $pa 下面的page
http://网址/index.php?page=5
*/
public function __construct($total, $listRows = 10, $pa = "") {
$this-total = $total;
$this-listRows = $listRows;
$this-uri = $this-getUri($pa);
$this-page = !empty($_GET["page"]) ? $_GET["page"] : 1;//不传入page,则默认显示首页
$this-pageNum = ceil($this-total / $this-listRows);
$this-limit = $this-setLimit();
}
//设置每页显示的条数
private function setLimit() {
return "Limit " . ($this-page - 1) * $this-listRows . ", {$this-listRows}";
}
//获得URL地址
private function getUri($pa) {
$url = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], '?') ? '' : "?") . $pa;
$parse = parse_url($url);
if (isset($parse["query"])) {
parse_str($parse['query'], $params);
unset($params["page"]);
$url = $parse['path'] . '?' . http_build_query($params);
}
return $url;
}
//魔术方法,
public function __get($args) {
if ($args == "limit")
return $this-limit;
else
return null;
}
//页面开始的条数
private function start() {
if ($this-total == 0)
return 0;
else
return ($this-page - 1) * $this-listRows + 1;
}
//页面结束的条数
private function end() {
return min($this-page * $this-listRows, $this-total);
}
/*设置首页*/
private function first() {
$html = "";
if ($this-page == 1)
$html.=' '.$this-config["first"].' ';
else
$html.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page=1\")'{$this-config["first"]}/a ";
//$html.=" a href='{$this-uri}page=1'{$this-config["first"]}/a ";
return $html;
}
/*设置上一页*/
private function prev() {
$html = "";
if ($this-page == 1)
$html.=' '.$this-config["prev"].' ';
else
$html.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page=" . ($this-page - 1) . "\")'{$this-config["prev"]}/a ";
//$html.=" a href='{$this-uri}page=".($this-page-1)."'{$this-config["prev"]}/a ";
return $html;
}
//页码列表【首页】【2】【3】…………【尾页】
private function pageList() {
$linkPage = "";
$inum = floor($this-listNum / 2);
for ($i = $inum; $i = 1; $i--) {
$page = $this-page - $i;
if ($page 1)
continue;
$linkPage.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page={$page}\")'{$page}/a ";
}
$linkPage.=" {$this-page} ";
for ($i = 1; $i = $inum; $i++) {
$page = $this-page + $i;
if ($page = $this-pageNum)
$linkPage.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page={$page}\")'{$page}/a ";
else
break;
}
return $linkPage;
}
/*设置下一页*/
private function next() {
$html = "";
if ($this-page == $this-pageNum)
$html.=' '.$this-config["next"].' ';
else
$html.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page=" . ($this-page + 1) . "\")'{$this-config["next"]}/a ";
//$html.=" a href='{$this-uri}page=".($this-page + 1)."'{$this-config["next"]}/a ";
return $html;
}
/*设置尾页*/
private function last() {
$html = "";
if ($this-page == $this-pageNum)
$html.=' '.$this-config["last"].' ';
else
$html.=" a href='javascript:void(0)' onclick='showPage(\"{$this-uri}page=" . ($this-pageNum) . "\")'{$this-config["last"]}/a ";
//$html.=" a href='{$this-uri}page=.(this-pageNum).'{$this-config["last"]}/a ";
return $html;
}
/*设置页面跳转*/
private function goPage() {
return
' input type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value' . $this-pageNum . ')?' . $this-pageNum . ':this.value;showPage(\'' . $this-uri . 'page=\'+page+\'\')}" value="' . $this-page . '" style="width:25px"
input type="button" value="GO" onclick="javascript:var page=(this.previousSibling.value' . $this-pageNum . ')?' . $this-pageNum . ':this.previousSibling.value;showPage(\'' . $this-uri . 'page=\'+page+\'\')" ';
}
//页面列表配置选项
function fpage($display = array(0, 1, 2, 3, 4, 5, 6, 7, 8)) {
$html[0] = " 共有b{$this-total}/b{$this-config["header"]} ";
$html[1] = " 每页显示b" . ($this-end() - $this-start() + 1) . "/b条,本页b{$this-start()}-{$this-end()}/b条 ";
$html[2] = " b{$this-page}/{$this-pageNum}/b页 ";
$html[3] = $this-first();
$html[4] = $this-prev();
$html[5] = $this-pageList();
$html[6] = $this-next();
$html[7] = $this-last();
$html[8] = $this-goPage();
$fpage = '';
foreach ($display as $index) {
$fpage.=$html[$index];
}
return $fpage;
}
}
2 数据显示
?php
//链接数据库
//获得具体信息
//分页显示
header("content-type:text/html;charset=utf-8");
$link = mysql_connect('localhost','root','111111');
mysql_select_db('shop', $link);
mysql_query("set names utf8");
$css = eof
style type="text/css"
table {border:1px solid black; width:700px; margin:auto; border-collapse:collapse;}
td {border:1px solid black; }
/style
eof;
echo $css;
echo "
table
trtd序号/tdtd名称/tdtd数量/tdtd价格/tdtd时间/td/tr
";
//1 引入分页类
include "./Pagination.php";
//2. 获得信息总条数
$sql = "select * from sw_goods";
$qry = mysql_query($sql);
$total = mysql_num_rows($qry);
$per = 7;
//3. 实例化分页类对象
$page_obj = new Pagination($total,$per);
//4. 拼装sql语句,获得每页信息
//利用page_obj实现limit的灵活设置
//$page_obj - limit;
$sqla = "select * from sw_goods ".$page_obj-limit;
$qrya = mysql_query($sqla);
//5. 获得页面列表
$pagelist = $page_obj - fpage(array(3,4,5,6,7,8));
$i=1;
while($rsta = mysql_fetch_assoc($qrya)){
echo "tr";
echo "td".$i++."/td";
echo "td".$rsta['goods_name']."/td";
echo "td".$rsta['goods_number']."/td";
echo "td".$rsta['goods_price']."/td";
echo "td".date("Y-m-d H:i:s",$rsta['goods_create_time'])."/td";
echo "/tr";
}
echo "trtd colspan=5".$pagelist."/td/tr";
echo "/table";
3 ajax无刷新分页实现
open(‘get','http://网址/index.php?page=2')
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""
html
head
title新建网页/title
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
meta name="description" content="" /
meta name="keywords" content="" /
script type="text/javascript"
//获得分页信息ajax函数
function showPage(myurl){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState==4){
var rst = document.getElementById("result");
rst.innerHTML = xhr.responseText;
}
}
xhr.open("get",myurl);
xhr.send(null);
}
window.onload = function(){
showPage("./data1.php"); //获得分页信息
//showPage("./data.php?page=2");
}
/script
style type="text/css"
/style
/head
body
h2ajax无刷新分页效果/h2
div id="result"/div
/body
/html
script type="text/javascript"
document.write(new Date()+"br /");
document.write(new Date()+"br /");
document.write(new Date()+"br /");
document.write(new Date()+"br /");
/script
Q2: PHP怎么实现无刷新添加记录
FORM里面设置TARGET,提交的页面执行的内容可以定向到一个隐藏的IFRAME,里面使用JSCRIPT语句ALERT反馈保存成功,录入页面没有刷新,也可以小改动在此提交,新存一条记录。
PHP离不开JS和HTML,结合起来用。
Q3: PHP无刷新存数据时出现乱码
//add.php
//写入之前先这样转一下变量即可。
//原因很简单。无刷新提交来的都是 U8 编码。转成GB2312就行了。
$txt =iconv('UTF-8','GB2312',$txt);
Q4: PHP怎样做到无刷新读取数据库中的内容显示出来。本人菜鸟一个!
要图方便的话,去引用个Jquery文件,然后在页面触发AJAX方法,往一个地址发送请求和携带的数据,接收请求成功后返回的数据,再使用js在当前页重新拼接html代码,覆盖原来的。
Q5: 用php做得网页,当数据库有数据录入的时候,想自动在页面上无刷新提示有信息录入该怎么做
可以直接用Timer控件。
前台:
asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" /asp:Timer
asp:Label ID="Label1" runat="server" Text=""/asp:Label
/ContentTemplate
/asp:UpdatePanel
后台:
protected void Timer1_Tick(object sender, EventArgs e)
{
//读取数据库,判断是否有数据更新,有则弹出消息提示 }
php无刷新数据库的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php无刷新分页、php无刷新数据库的信息别忘了在本站进行查找喔。





