ajax+php+mysql无刷新分页代码(1/2)

 更新时间:2016年11月25日 16:28  点击:2093
 代码如下 复制代码
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
  2  <html>
  3  <head>
  4     <title>投票结果</title>
  5     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6
  7  <script type="text/网页特效">
  8
  9     function getxmlhttpobject()
 10 {
 11   var xmlhttp=null;
 12   try
 13     {
 14     // firefox, opera 8.0+, safari
 15      xmlhttp=new xmlhttprequest();
 16     }
 17   catch (e)
 18     {
 19     // internet explorer
 20     try
 21       {
 22       xmlhttp=new activexobject("msxml2.xmlhttp");
 23       }
 24     catch (e)
 25       {
 26       xmlhttp=new activexobject("microsoft.xmlhttp");
 27       }
 28     }
 29   return xmlhttp;
 30 }
 31 function checkajax(){
 32    xmlhttp=getxmlhttpobject()
 33  
 34   if (xmlhttp==null)
 35     {
 36     alert ("您的浏览器不支持ajax!");
 37     return ;
 38     }else
 39     {
 40        return xmlhttp;
 41     }
 42 }
 43 function preshow(){
 44     ajaxobj = checkajax();
 45     var url = "page.php?page=1";
 46 ajaxobj.onreadystatechange=statechanged;
 47 ajaxobj.open("get",url,true);
 48 ajaxobj.send(null);
 49 }
 50 function showhint1(str)
 51 {
 52     ajaxobj = checkajax();
 53     document.getelementbyid("msg").innerhtml="正在读取数据……";
 54
 55 var url = str;
 56 ajaxobj.onreadystatechange=statechanged;
 57 ajaxobj.open("get",url,true);
 58 ajaxobj.send(null);
 59
 60 }

 

这款批量生成缩略图代码可以生成指定大小的小图哦,并且支持文件批量上传。

这款教程会用到php文件
view.php
config.php
funs.php
index.php


功能:
-----------------------
1.为文件夹里的图片生成指定大小缩略图
2.列出子文件夹, 可以指定生生某文件夹生成
3.为方便不同大小的缩图生成,图片保存到新的目录,而目录结构不变

实现:
-----------------------
1.图片原文件夹   $image
2.处理后保存在   $newimage
 保持目录结构和文件名不变(方便调用)
3.如果在新的文件夹里图片已经存在,直接跳过

操作界面:
-----------------------
1.$image 输入框
2.$newimage 输入框(若没填写,刚为当前目录平级的以缩略大小为文件名的目录)
3.按扭"搜索",列出所有文件夹,生成缓存,写到文件.
4.生成.     生成子目录

*/
?>
//index.php代码

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=gb2312">
  <title>生成缩略图</title>
</head>
 <body>
<?php
/* +-------------------------------------------------------------+
 * | copyright (c) 2008-2009 yese.in all rights reserved.       
 * +-------------------------------------------------------------+
 * | author: wbsifan <wbsifan@163.com>   <qq:29500196>          
 * +-------------------------------------------------------------+ 
 * | filename : index.php v0.1
 * | update   : 2008-07-01
 * | content  : 生成缩略图 
 * +-------------------------------------------------------------+
 */

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net1999/xhtml">

<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type" />
<title>多个文件上传(php+网页特效可动态增加文件上传框)</title>
<script language="网页特效" type="text/网页特效">
function addinput()//增加input节点
{
var input=document.createelement('input');//创建一个input节点
var br=document.createelement('br');//创建一个br节点
input.setattribute('type','file');// 设置input节点type属性为file
input.setattribute('name','pic[]');//设置input节点 name属性为files[],以 数组的方式传递给服务器端
document.form1.appendchild(br);//把节点添加到 form1表单中
document.form1.appendchild(input);
}
</script>
</head>
<?php
if($_post['sub'])
{
$ftype=array('image/jpg','image /jpeg','imgage/png','image/pjpeg','image/gif');//允许上传的文件类型
$files=$_files['files'];
$fnum=count($files['name']); //取得上传文件个数
for($i=0;$i<$fnum;$i++)
{
   if($files['name'][$i]!=''&&is_uploaded_file($files['tmp_name'][$i]))
   {
    if(in_array($files['type'][$i],$ftype))//判断文件是否是允许的类型
    {
     $fname='upfile/'.rand(0,10000).time().substr($files['name'] [$i],strrpos($files['name'][$i],'.'));//自动命名
     move_uploaded_file($files['tmp_name'][$i],$fname);
     echo '<br/>文件上传成功!';
    }
    else
    {
     echo '<br/>不允许的文件类型!';
    }
   }
   else
   {
    echo '<br/>该文件不存在!';
   }
}

}
?>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data" >
    <input type="file" name="pic[]" />
<input type="submit" name="sub" value="上传"/>
</form>
<a href="#" onclick="addinput()">再上传一张</a>
</body>

</html>

直接用php创建word文档代码(系统无需安装word软件) 使用方法: 首先用$word->start()表示要生成word文件了。 然后你可以输出任何的HTML代码,不论是从文件读过来再写到这里, 还是直接在这里输出HTML,都没有关系。

等你输出完毕后,用$word->save($path)方法,其中$path是你想 生成的word文件的名称(可以给出完整的路径).当你使用了$word->save() 方法后,这后面的任何输出都和word文件没有关系了,也就是说word的生成 工作就完成了。之后就和你平常使用php的方式一样拉。随便你输出什么东西, 都直接在浏览器里输出,而不会写到word里面去。

*/

 代码如下 复制代码

class word

function start()
{
ob_start();
print'<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/tr/rec-html40">';

}

function save($path)
{

print "</html>";
$data = ob_get_contents();

ob_end_clean();

$this->wirtefile ($path,$data);
}

function wirtefile ($fn,$data)
{

$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}

}
//生成word调用方法
include("word.php");
$word=new word;
$word->start();

关于购物车,这个是在电子商务方面使用的比较多,用户选择好自己的商品需要保存起来,最后去收银台,这很像我们实际生活的超市,所以我现来写一个简单的php购物车实例代码,比较详细只要一步步,处理好就OK了。

些购物车会用到php文件
 main.php 显示商品
 additem.php把商品加入购物车
 cearcart.php删除购物车中的商品
 shoppingcart.php 操作类
 
用户的数据库教程有

 代码如下 复制代码
 inventory
  create table inventory (
    product tinytext not null,
    quantity tinytext not null,
    id int(4) default '0' not null auto_increment,
    description tinytext not null,
    price float(10,2) default '0.00' not null,
    category char(1) default '' not null,
    key id (id),
    primary key (id),
    key price (price)
  );
  insert into inventory values ('硬盘','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板www.111cn.net','3','4','asus','5000','2');
  insert into inventory values ('显示卡','6','5','64m','4500','1');
  insert into inventory values ('刻录机','4','6','52w','3000','1');
 
 shopping
  create table shopping (
    session tinytext not null,
    product tinytext not null,
    quantity tinytext not null,
    card tinytext not null,
    id int(4) default '0' not null auto_increment,
    key id (id),
    primary key (id)
  );
 shopper
 
  create database shopper;
  use shopper;
  create table shopping (
    session tinytext not null,
    product tinytext not null,
    quantity tinytext not null,
    card tinytext not null,
    id int(4) default '0' not null auto_increment,
    key id (id),
    primary key (id)
  );
  create table inventory (
    product tinytext not null,
    quantity tinytext not null,
    id int(4) default '0' not null auto_increment,
    description tinytext not null,
    price float(10,2) default '0.00' not null,
    category char(1) default '' not null,
    key id (id),
    primary key (id),
    key price (price)
  );
  insert into inventory values ('硬盘','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板111cn.net','3','4','asus','5000','2');
  insert into inventory values ('显示卡','6','5','64m','4500','1');
  insert into inventory values ('刻录机','4','6','52w','3000','1');

*/

//main.php 显示购物车所有商品

 代码如下 复制代码

include("shoppingcart.php");
$cart = new cart;
$table="shopping";

/* 查询并显示所有存货表中的信息 */
    $query = "select * from inventory";
    $invresult = mysql教程_query($query);
    if (!($invresult)) {
       echo "查询失败<br>";
       exit;
    }
    echo "以下产品可供订购∶";
    echo "<table border=0>";
    echo "<tr><td bgcolor=#aaccff>产品编号</td><td bgcolor=#aaccff>产品名称</td><td bgcolor=#aaccff>单价</td>";
    echo "<td bgcolor=#aaccff>剩余数量</td><td bgcolor=#aaccff>产品描述</td><td bgcolor=#aaccff>放入购物车</td></tr>";
    while($row_inventory = mysql_fetch_object($invresult)) {
    echo "<tr><td bgcolor=#aaccff>".$row_inventory->id."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->product."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->price."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->quantity."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->description."</td>";
    echo "<td bgcolor=#aaccff><a href='additem.php?product=".$row_inventory->product."'><img border='0' src='cart.gif' width='81' height='17'></a></td></tr>";
    }
    echo "</table>";
    echo "<br>购物车中产品的数量∶".$cart->quant_items($table, $session);
    echo "<br><br><a href='clearcart.php'><img border='0' src='car.gif'></a>清空购物车";

 

[!--infotagslink--]

相关文章

  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • jQuery+PHP发布的内容进行无刷新分页(Fckeditor)

    这篇文章将使用jQuery,并结合PHP,将Fckeditor发布的内容进行分页,并且实现无刷新切换页面。 本文假设你是WEB开发人员,掌握了jQuery和PHP相关知识,并且熟知Fckeditor的配置和使用。...2015-10-23
  • 解决vue刷新页面以后丢失store的数据问题

    这篇文章主要介绍了解决vue刷新页面以后丢失store的数据问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-12
  • 解决vuex数据页面刷新后初始化操作

    这篇文章主要介绍了解决vuex数据页面刷新后初始化操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-26
  • java后台实现js关闭本页面,父页面指定跳转或刷新操作

    这篇文章主要介绍了java后台实现js关闭本页面,父页面指定跳转或刷新操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-16
  • php+ajax制作无刷新留言板

    本文就是和大家分享一款由php结合ajax实现的无刷新留言板,先给大家看一下最后的效果图:数据库连接代码如下: <&#63;php$conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误");mysql_select_db("d...2015-10-30
  • 基于jquery实现表格无刷新分页

    这篇文章主要介绍了基于jquery实现表格无刷新分页,功能实现了前端排序功能,增加了前端搜索功能,感兴趣的小伙伴们可以参考一下...2016-01-08
  • Vue 中获取当前时间并实时刷新的实现代码

    这篇文章主要介绍了Vue 中获取当前时间并实时刷新,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-05-13
  • vue实现在进行增删改操作后刷新页面

    这篇文章主要介绍了vue实现在进行增删改操作后刷新页面,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-05
  • C#实现刷新桌面的方法

    这篇文章主要介绍了C#实现刷新桌面的方法,涉及C#基于shell32.dll动态链接库实现系统桌面刷新的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • 纯javascript实现简单下拉刷新功能

    代码很简单,实现的功能却很实用,直接奉上代码CSS:复制代码 代码如下: <meta charset="utf-8" /> <title>Pull to Refresh</title> <meta name="viewport" content="width=device-width,height=device-height,inital-scal...2015-03-15
  • Springboot使用thymeleaf动态模板实现刷新

    这篇文章主要介绍了Springboot使用thymeleaf动态模板实现刷新,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-08-31
  • Ionic如何实现下拉刷新与上拉加载功能

    在日常项目开发中我们经常见到下拉刷新上拉加载的功能,接下来通过本文给大家介绍ionic如何实现下拉刷新与上拉加载的相关资料,需要的朋友可以参考下...2016-06-12
  • vue相同路由跳转强制刷新该路由组件操作

    这篇文章主要介绍了vue相同路由跳转强制刷新该路由组件操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-05
  • 快速解决PHP+MYSQL 出现乱码的解决方法

    如果你mysql查询出来乱码的话,多半是中文乱码了了,这种问题解决办法只需要统一页面与数据连接时的编码设置就可以解决,下面总结了些方法。 在mysql_connect后面加一...2016-11-25
  • ajax+php 无刷新数据调用经典实例

    <!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/1...2016-11-25
  • python输出结果刷新及进度条的实现操作

    这篇文章主要介绍了python输出结果刷新及进度条的实现操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-13
  • C#利用子线程刷新主线程分享教程

    本文将详细介绍C#利用子线程如何刷新主线程,需要了解更多的朋友可以参考下...2020-06-25
  • jQuery禁用键盘后退屏蔽F5刷新及禁用右键单击

    这篇文章主要介绍了jQuery禁用键盘后退、屏蔽F5刷新、禁用右键单击功能等快捷方法,感兴趣的小伙伴们可以参考一下...2016-01-24
  • php iframe 无刷新文件上传代码

    其它原理很简单,利用form表单的target属性和iframe来实现的,打开为iframe试就行了,返回就利用js判断php教程运行后返回的参数是不是成功 一、上传文件的一个php方法。...2016-11-25