
正文
php数据库分批自动处理 php怎么操作数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP批量处理checkbox以及存数据库
首先你这个页面是html类型的php数据库分批自动处理,里面的php得不到执行。
所以你把这个子窗口改成child.php,form的action属性就设为child.php就能实现第2项功能了.
第一项功能的实现需要在页面里面加一个判断语句,如果参数$lang[]不为空则执行一段代码,就是一个建表的操作php数据库分批自动处理:
$conn = mysql_connect("localhost","root","password") or die("无法连接数据库");
mysql_select_db("webjx",$conn) or die("无法连接数据库webjx");
$sql = "create table webjx_table(
ids integer not null auto_increment ,
primary key(ids)
)";
$mysql_query($sql) or die(mysql_error());
相关问答
Q1: PHP中用ajax和递归可以实现从数据库中分批取出数据么
百万级的数据库表php数据库分批自动处理,好像也不用这么麻烦吧?
直接写一个phpphp数据库分批自动处理,递归执行就差不多php数据库分批自动处理了php数据库分批自动处理,但是php.ini中,将memory_limit设置大一些,再将mysql.connect_timeout值加大些,max_execution_time设置的值大一些。
如果不想设置这些,在程序中使用 ini_set() 函数也是可以的,一开始先递归小一些做十几条,测试通过了再递归所有数据,然后等就行了。
在等待的过程中,php数据库分批自动处理你可以用phpmyadmin等工具查看实时进度,如果发现问题,重启web服务器进程,就中止运行了,然后再试。
Q2: Php如何分批处理数据
使用for循环
定义变量$i,配合select * from table where ………… limit $i,100
这样就可以了
我之前就做过,但因为换了工作,代码在之前的公司,否则就可以让你参考下了
另外,我觉得100太少了,最起码得改成1000才行
Q3: PHP显示很多数据库信息,如何自动分页呢?代码
这是我以前学php写的 哈哈 你可以看看
?php
/**
* 分页类
* 1.实例化分页类,例:mypage new page("SQL语句","每页显示记录条数");
* 2.调用类中的 genpage() 方法,返回分页生成的SQL语句;
* 3.执行新生成的SQL语句;
* 4.调用 showpage_1() 或 showpage_2() 方法显示分页的翻页(可也以自定义返回显示的方式)
* 实例:
* $page = new page("select * from ly",2);
* $sql=$page-genpage();
* $ar=mysql_query($sql);
* while($nu=mysql_fetch_array($ar)){
* echo $nu[0].'br';
* }
* $page-showpage_2();
*/
class page{
private $totalnum; //总记录数
private $pagecount; //总页数
private $f_pagenum; //当前页的第一条记录
private $sql;
private $page; //当前页
private $page_size; //每页显示数量
private $pagesql;
private $total;
private $url; //当前页url
private $beforepage; //上一页
private $nextpage; //下一页
function __construct($sql,$page_size){ //传入sql语句和每页显示条数
$this-sql=$sql;
$this-page_size=$page_size;
$this-page=is_numeric($_GET[page]);
$this-page=substr($this-page,0,10);
$this-page=mysql_real_escape_string($this-page);
if(ereg("^[0-9]*[1-9][0-9]*$",$this-page)!=1){
$this-page=1;
}
if($this-page99999999){
$this-page=1;
}
}
function genpage(){
//
// if(!$this-page){
// $this-page=1;
// }
$this-pagesql = strstr($this-sqlcz," from ");
$this-pagesql = "select count(*) as ids ".$this-pagesql;
$this-total=mysql_query($this-sql);
$this-totalnum=mysql_num_rows($this-total); //总记录数
$this-pagecount=ceil($this-totalnum/$this-page_size); //总页数
$this-f_pagenum=$this-page_size*($this-page-1); //当前页的第一条记录
$this-sql .=" limit $this-f_pagenum,$this-page_size ";
return $this-sql;
}
//替换url中的page的页数
function replace_page($npage){
$this-url=$_SERVER["REQUEST_URI"]; //获取当前url
$check = strpos($this-url, 'page='); //判断url中是否有page分页参数
if($check==false){ //如果没有page分页参数
if(strpos($this-url, '?')==false){ //判断是否url是否有“ ?”号,
$this-url=$this-url."?page=1"; //如果没有“ ?”号,说明之前url没有参数
}else{
$this-url=$this-url."page=1"; //如果有“ ?”号,说明有参数,追加参数要改用符号
}
}
$npage="page=".$npage; //跳转到的页
$zz='[page=\d*]';
return preg_replace($zz,$npage,$this-url); //正则替换掉url中的page参数,实现分页
}
//显示总页数
function show_all_page(){
return $this-pagecount;
}
//显示当前页
function show_current_page(){
return $this-page;
}
//显示首页和上一页
function show_firstAndup_page(){
if($this-page==1){
return "首页|上一页";
}else{
$this-beforepage=$this-page-1;
return "a href=".$this-replace_page(1)."首页/a|a href=".$this-replace_page($this-beforepage)."上一页/a";
}
}
//显示下一页和最后页
function show_lastAnddown_page(){
if(($this-page==$this-pagecount)||($this-pagecount==0)){
return "下一页|尾页";
}else{
$this-nextpage=$this-page+1;
return "a href=".$this-replace_page($this-nextpage)."下一页/a|a href=".$this-replace_page($this-pagecount)."尾页/a";
}
}
//循环显示页数
function show_loop_page(){
$shownum =10/2;
$startpage = ($this-page$shownum)?$this-page-$shownum:1;
$endpage = ($this-page+$shownum=$this-pagecount)?$this-page+$shownum:$this-pagecount;
for($i=$startpage;$i=$endpage;$i++)
{
if($i==$this-page) {
$a= " b[".($i)."]/b ";
}else{
$a= " a href=".$this-replace_page($i)."".($i)."/a ";
}
$b=$b.$a;
}
return $b;
}
//整体显示第一种方案
function showpage_1(){
return "共".$this-show_all_page()."页nbsp"."当前第".$this-show_current_page()."页nbsp".$this-show_firstAndup_page()."nbsp"
.$this-show_loop_page()."nbsp".$this-show_lastAnddown_page();
}
//整体显示第二种方案
function showpage_2(){
return $this-show_firstAndup_page()."nbsp".$this-show_loop_page()."nbsp".$this-show_lastAnddown_page();
}
}
?
php数据库分批自动处理的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php怎么操作数据库、php数据库分批自动处理的信息别忘了在本站进行查找喔。






