PHP批量生成數(shù)據(jù) php批量導(dǎo)入

PHP從數(shù)據(jù)庫讀取數(shù)據(jù)批量生成HTML

首先創(chuàng)建html文件??梢砸詉d字段作為文件名,你如果嫌短的話,再加上time()。

目前創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、元謀網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

如 $filename=$row[id].time."html";

然后以可寫的形式打開剛剛建立的文件,把讀出的數(shù)據(jù)內(nèi)容存放進(jìn)去。一個(gè)文件就建成了。如果建成批量的,在讀取數(shù)據(jù)表的時(shí)候,把代碼加到while循環(huán)里就好了。

php 批量生成html,txt文件的實(shí)現(xiàn)代碼

首先建立一個(gè)conn php的文件用來鏈接數(shù)據(jù)庫

復(fù)制代碼 代碼如下: ?php $link = mysql_connect("mysql_host" "mysql_user" "mysql_password" )or die("Could not connect : " mysql_error()); mysql_query("set names utf "); mysql_select_db("my_database") or die("Could not select database"); ?

php 批量生成

復(fù)制代碼 代碼如下: ?php require_once(“conn php”) $query = "SELECT id title introduce FROM my_table"; $result = mysql_query($query) or die("Query failed : " mysql_error()); /* 生成 HTML 結(jié)果 */ while ($row = mysql_fetch_array($result MYSQL_ASSOC)) { $id=$row[ id ]; $title=$row[ title ]; $introduce=$row[ introduce ]; $path="/$id "; $fp=fopen("template " "r"); //只讀打開模板 $str=fread($fp filesize("template "));//讀取模板中內(nèi)容 $str=str_replace("{title}" $title $str); $str=str_replace("{introduce}" $introduce $str);//替換內(nèi)容 fclose($fp); $handle=fopen($path "w"); //寫入方式打開新聞路徑 fwrite($handle strip_tags($introduce)); //把剛才替換的內(nèi)容寫進(jìn)生成的HTML文件 fclose($handle); //echo "a href=/$id 生成成功/a" "br"; } /* 釋放資源 */ mysql_free_result($result); mysql_close($link); ?

template 文件內(nèi)容

復(fù)制代碼 代碼如下: !DOCTYPE PUBLIC " //W C//DTD XHTML Transitional//EN" " xmlns=" head meta equiv="Content Type" content="text/; charset=utf " / title{title}/title /head body {introduce} /body /

php 批量生成txt

復(fù)制代碼 代碼如下: lishixinzhi/Article/program/PHP/201311/20863

PHP批量生成注冊(cè)碼并保存到數(shù)據(jù)庫

for ($i=0; $i$批量生成數(shù)量; $i ){

//$key_str 賦值

$key_str = $file[mt_rand($start_num, $end_num)].$limiter.$file[mt_rand($start_num, $end_num)].$limiter.$file[mt_rand($start_num, $end_num)].$limiter.$file[rand_num($start_num, $end_num)];

//判斷是否重復(fù)

$sql = "select * from 表名 where 字段名=‘$key_str ’";

$rec = mysql_query($sql);

$num = mysql_fetch_array($rec);

//如果行數(shù)為0,說明$key_str 不重復(fù),可以插入

if(!$num){

//這里地方是寫入數(shù)據(jù)庫的語句}

}

Thinkphp怎么批量添加數(shù)據(jù)

?php

class FileAction extends Action {

public function Index()

{

//print_r(__URL__);

$file = M('file');

$list = $file-select();

$this-assign('filelist',$list);

$this-display();

}

public function upload()

{

//文件上傳的地址上傳給它,并且上傳完成后返回一個(gè)信息,讓其寫入數(shù)據(jù)庫

//如果$_FILES為空的畫,我就讓action給出一個(gè)錯(cuò)誤提示,告訴用戶必須選擇上傳文件。如果有上傳文件,則調(diào)用up方法

//$_FILES = $this-_post('file');

//print_r($_FILES);

if (empty($_FILES)) {

$this-error('必須選擇上傳文件');

}else {

$a = $this-Up();

//print_r($a);

if (isset($a)) {

//寫入數(shù)據(jù)庫方法

if($this-c($a)) {

$this-success('上傳成功');

}else {

$this-error('寫入數(shù)據(jù)庫失敗');

}

}else {

$this-error('上傳文件有異常請(qǐng)與系統(tǒng)管理員聯(lián)系');

}

}

}

private function c($data)

{

//print_r($data);

$file=M('file');

$num = '0';

for($i = 0; $i count($data)-1; $i++) {

$data['filename']=$data[$i]['savename'];

if( $file-data($data)-add())

{

$num++;

}

}

if($num==count($data)-1)

{

return true;

}else {

return false;

}

}

// private function c($data)

// {

// $file = M('file');

// $data['filename'] = $data[0]['savename'];

// if ($file-data($data)-add()) {

// return true;

// }else {

// return false;

// }

// }

//在這個(gè)方法當(dāng)中,完成與thinkphp相關(guān)的,文件上傳類的調(diào)用

private function Up()

{

//echo '模擬上傳';

//基本上傳功能

//批量上傳功能

//生成圖片縮略圖

//自定義參數(shù)上傳

//上傳檢測(cè)(大小,后綴,mime類型)

//支持覆蓋方式上傳

//上傳類型,附件大小,上傳路徑定義

//支持hash或者日期子目錄保存上傳文件

//上傳圖片的安全性檢測(cè)

//對(duì)上傳文件的hash檢測(cè)

//上傳文件名自定義規(guī)范

import('@.ORG.UploadFile');

import('@.ORG.Image');

$upload = new UploadFile();

$upload-maxSize = '1000000'; //指上傳文件大小,默認(rèn)為-1,不限制大?。╞ytes)

$upload-savePath = './Public/'; //上傳保存到什么地方?路徑建議保存到入口文件平級(jí)或平級(jí)目錄的子目錄

$upload-saveRule = 'uniqid'; //上傳文件的文件名保存規(guī)則 time uniqid(默認(rèn)) com_create_guid

$upload-hashType = 'md5_file';

$upload-autoCheck = true; //是否自動(dòng)檢測(cè)附件 默認(rèn)true

$upload-uploadReplace = true; //如果存在同名文件是否進(jìn)行覆蓋

$upload-allowExts = array('jpg','jpeg','png','gif'); //允許上傳的文件后綴

$upload-allowPath = array('image/png','image/jpg','image/pjpeg','image/gif','image/jpeg'); //檢測(cè)mime類型

$upload-thumb = true; // 是否開啟圖片文件縮略

$upload-thumbMaxWidth = '300,500';//縮略圖最大寬度

$upload-thumbMaxHeight = '200,400';//最大高度

$upload-thumbPrefix = 's-,m-';//縮略圖文件前綴

//$upload-thumbSuffix = '_s,_m';//文件后綴

//$upload-thumbPath = '';//如果留空直接上傳至

//$upload-thumbFile 在數(shù)據(jù)庫中也存一個(gè)文件名即可

$upload-thumbRemoveOrigin = 1; //如果生成縮略圖,是否刪除原圖

//$upload-autoSub 是否使用子目錄進(jìn)行保存上傳文件

//$upload-subType='' 子目錄創(chuàng)建方式默認(rèn)為hash 也可以為date

//$upload-dateFormat 子目錄方式date的指定日期格式

//$upload-hashLevle

//upload() 如果上傳成功返回true,失敗返回false

if ($upload-upload()) {

$info = $upload-getUploadFileInfo();

return $info;

}else {

//是專門來獲取上傳的錯(cuò)誤信息的

$this-error($upload-getErrorMsg());

}

}

}

?

php 批量添加數(shù)據(jù)

在HTML里這樣寫:

form?........

input?type="text"?name="haoma[]"?/

input?type="text"?name="haoma[]"?/

input?type="text"?name="haoma[]"?/

....

第N個(gè)

PHP中這樣操作:

foreach($_POST['haoma']?as?$v){

$sql="insert?into?haoma?values('',$v)";

.......

}

當(dāng)然這樣寫一條一條的效率是會(huì)慢,再改一下

foreach($_POST['haoma']?as?$v){

$values.="('',$v),";

}

$values=substr($values,0,strlen($values)-1);

$sql="insert?into?haoma?values?$values";

......

下面的query我就不寫了

網(wǎng)站題目:PHP批量生成數(shù)據(jù) php批量導(dǎo)入
文章URL:http://muchs.cn/article44/hjsghe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)網(wǎng)站營(yíng)銷、關(guān)鍵詞優(yōu)化、標(biāo)簽優(yōu)化、網(wǎng)站排名、營(yíng)銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名