当前位置: 编程技术>php
本页文章导读:
▪如何将数据从文本导入到mysql
access中可以将文本中的数据轻松导入表中,mysql中用起来没那么方便,其实起来也很简单。 首先将数据记录按行处理好用特定的字符分开如:“,” 记录形如: aaa,bbb,ccc,ddd,eee fff,ggg,hhh,iii,jjj.........
▪PHP个人网站架设连环讲(三)
三 首页新闻发布,让你更新更轻松(中) 上次我们做了一个文件头(至于文件尾,请大家自己做,假设为tail.php),一个函数的模块,现在,我们来一个基本功能的实现,也就是动态发布.........
▪杏林同学录(九)
班级成员留言簿管理: class/notebook/delnote.php <?php session_start(); if(!session_is_registered("superlogin"))//检查是否注册 { echo "<a href='/superadmin.html'>请重新进行管理员登陆<BR>"; exit; } include .........
[1]如何将数据从文本导入到mysql
来源: 互联网 发布时间: 2013-11-30
access中可以将文本中的数据轻松导入表中,mysql中用起来没那么方便,其实起来也很简单。
首先将数据记录按行处理好用特定的字符分开如:“,”
记录形如:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
就行,建立loaddate.php
<?php
$hostname="localhost";
$username="yourname";
$password="yourpwd";
$dbname="yourdb";
mysql_connect($hostname,$username,$password);
mysql_select_db("$dbname");
$mydate=file("yourdate.txt");
$n=count($mydate);
for($i=0;$i<$n;$i++){
$date=explode(",",$mydate[$i]);
$str="insert into ip values('$date[0]','$date[1]','$date[2]','$date[3]','$date[4]')";//
mysql_query($str);
}
mysql_close();
echo "ok!";
?>
运行loaddate.
首先将数据记录按行处理好用特定的字符分开如:“,”
记录形如:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
就行,建立loaddate.php
<?php
$hostname="localhost";
$username="yourname";
$password="yourpwd";
$dbname="yourdb";
mysql_connect($hostname,$username,$password);
mysql_select_db("$dbname");
$mydate=file("yourdate.txt");
$n=count($mydate);
for($i=0;$i<$n;$i++){
$date=explode(",",$mydate[$i]);
$str="insert into ip values('$date[0]','$date[1]','$date[2]','$date[3]','$date[4]')";//
mysql_query($str);
}
mysql_close();
echo "ok!";
?>
运行loaddate.
[2]PHP个人网站架设连环讲(三)
来源: 互联网 发布时间: 2013-11-30
三 首页新闻发布,让你更新更轻松(中)
上次我们做了一个文件头(至于文件尾,请大家自己做,假设为tail.php),一个函数的模块,现在,我们来一个基本功能的实现,也就是动态发布啦
<?php
include("makestr.php";
include("head.php");
$newspath="/announce/"; //以文本文件存放的新闻文件的目录
$newsfile=array();//准备新闻数组
$hd=dir($newspath); //目录句柄
while($filename=$hd->read()){ //获取全部文件
$s=strtolower($filename);
if(strstr($s,".txt")){
//检测最新的修改日期
$lastchanged=fileatime($newspath.$filename);
$newsfile[$filename]=$lastchanged;
}
}
arsort($newsfile); //文件按时间排序
//输出文件
for(reset($newsfile);$key=key($newsfile);next($newsfile))
{$fa=file($newspath.$key);
$n=count($fa);
echo "<p>".date("d.m.Y-H:i:s".$newsfile[$key])."<br>\n";
for($i=0;$i<$n;$i=$i+1){
$s=chop($fa[$i]);//去除空格
$s=htmlspecialchars($s);
print $s."</p>\n";
}
}
$hd->close(); //释放句柄
include("tail.php");
?>
这样,将你的新闻文本传上你根目录的annouce子目录下,就可以方便发布新闻了。但真正的方便还不在于这,比如说,当新闻过时的时候,程序能自动删除它,多好。不用ftp,直接在线写下要新发的公告,多方便。好了,且听下回分解。
上次我们做了一个文件头(至于文件尾,请大家自己做,假设为tail.php),一个函数的模块,现在,我们来一个基本功能的实现,也就是动态发布啦
<?php
include("makestr.php";
include("head.php");
$newspath="/announce/"; //以文本文件存放的新闻文件的目录
$newsfile=array();//准备新闻数组
$hd=dir($newspath); //目录句柄
while($filename=$hd->read()){ //获取全部文件
$s=strtolower($filename);
if(strstr($s,".txt")){
//检测最新的修改日期
$lastchanged=fileatime($newspath.$filename);
$newsfile[$filename]=$lastchanged;
}
}
arsort($newsfile); //文件按时间排序
//输出文件
for(reset($newsfile);$key=key($newsfile);next($newsfile))
{$fa=file($newspath.$key);
$n=count($fa);
echo "<p>".date("d.m.Y-H:i:s".$newsfile[$key])."<br>\n";
for($i=0;$i<$n;$i=$i+1){
$s=chop($fa[$i]);//去除空格
$s=htmlspecialchars($s);
print $s."</p>\n";
}
}
$hd->close(); //释放句柄
include("tail.php");
?>
这样,将你的新闻文本传上你根目录的annouce子目录下,就可以方便发布新闻了。但真正的方便还不在于这,比如说,当新闻过时的时候,程序能自动删除它,多好。不用ftp,直接在线写下要新发的公告,多方便。好了,且听下回分解。
[3]杏林同学录(九)
来源: 互联网 发布时间: 2013-11-30
班级成员留言簿管理: class/notebook/delnote.php
<?php
session_start();
if(!session_is_registered("superlogin"))//检查是否注册
{
echo "<a href='/superadmin.html'>请重新进行管理员登陆<BR>";
exit;
}
include ("../config.php");
if($del==1){ //判断是否要删除
mysql_query("delete from notebook where time='$time'",$db); //以留言时间为删除标志
echo "删除成功!";
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>删除留言</TITLE>
<style type="text/css">
<!--
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
$result = mysql_query("SELECT * FROM notebook",$db);
$row=mysql_num_rows($result);//查看结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){$page=1;}
$p=ceil($max/10);
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);} else {$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebook ORDER BY time DESC limit $low,$x",$db);
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><img src="/image/classlogo.gif" width="224" height="60" border="0"></td>
<td height="62" width="66%">
<div align="center"><img src="/image/note.gif" width="410" height="60"><img src="/image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="28%" ><a href="/guest.html" >首页</a>
> <a href="/blog_article/index.html" >留言簿</a></td>
<td width="56%" >
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n++){
echo "<a href=/blog_article/index/page/$n/gt;$n/lt;/a/gt;.html";
}
echo "页";
?>
</td>
<td width="16%"><a href="/blog_article/index.html" >查看留言</a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i++) {
$user=mysql_result($result,$i,'user');
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
$yresult = mysql_query("SELECT * FROM user where user='$user'",$db);//读取成员数据库
$name=mysql_result($yresult,0,'name');
$signature=mysql_result($yresult,0,'signature');//读取个人签名
$email=mysql_result($yresult,0,'email');
$face=mysql_result($yresult,0,'face');
$face='../image/face/icon'.$face;
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height=107' bordercolor='#FFFFFF'> <tr bgcolor='#eeeeee'>";
echo "<td width='10%' height='33' bgcolor='#eeeeee' > <img src='/blog_article/$face.gif' width='32' height='32'></td>";
echo "<td width='16%' height='33' bgcolor='#eeeeee' >留言人:$name</td>";
echo "<td width='41%' height='33' bgcolor='#eeeeee' >发表于:$time</td>";
echo "<td width='12%' height='33' bgcolor='#eeeeee' ><a href='mailto:$email'><img src='/image/email.gif' width='16' height='16' border=0></a></td>";
echo "<td width='21%' height='33' ><img src='/image/ip.gif' width='13' height='15'> $ip <a href='/blog_article/$PHP_SELF/del/1/amp;time/$time.html'><img src='/image/del.gif' width='16' height='16' border=0></a></td> </tr> <tr>";
echo "<td colspan='5' height='33'>标题:$title</td> </tr>";
echo "<tr bgcolor='#ffffff'><td colspan='5' height='37'>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>
客人留言簿管理: class/notebookg/delnote.php
<?php
session_start();
if(!session_is_registered("superlogin"))//检查是否注册
{
echo "<a href='/superadmin.html'>请重新进行管理员登陆<BR>";
exit;
}
include ("../config.php");
if($del==1){ //判断是否要删除
mysql_query("delete from notebookg where time='$time'",$db); //以留言时间为删除标志
echo "删除成功!";
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>删除留言</TITLE>
<style type="text/css">
<!--
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
$result = mysql_query("SELECT * FROM notebookg ",$db);
$row=mysql_num_rows($result);//查看结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){$page=1;}
$p=ceil($max/10);
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);} else {$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebookg ORDER BY time DESC limit $low,$x",$db);
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><img src="/image/classlogo.gif" width="224" height="60" border="0"></td>
<td height="62" width="66%">
<div align="center"><img src="/image/note.gif" width="410" height="60"><img src="/image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="28%" ><a href="/guest.html" >首页</a>
> <a href="/blog_article/index.html" >留言簿</a></td>
<td width="56%" >
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n++){
echo "<a href=/blog_article/index/page/$n/gt;$n/lt;/a/gt;.html";
}
echo "页";
?>
</td>
<td width="16%"><a href="/blog_article/index.html" >查看留言</a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i++) {
$email=mysql_result($result,$i,'email');
$face=mysql_result($result,$i,'face');
$face='../image/face/icon'.$face;
$name=mysql_result($result,$i,'name');
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height=107' bordercolor='#FFFFFF'> <tr bgcolor='#eeeeee'>";
echo "<td width='10%' height='33' bgcolor='#eeeeee' > <img src='/blog_article/$face.gif' width='32' height='32'></td>";
echo "<td width='16%' height='33' bgcolor='#eeeeee' >留言人:$name</td>";
echo "<td width='41%' height='33' bgcolor='#eeeeee' >发表于:$time</td>";
echo "<td width='12%' height='33' bgcolor='#eeeeee' ><a href='mailto:$email'><img src='/image/email.gif' width='16' height='16' border=0></a></td>";
echo "<td width='21%' height='33' ><img src='/image/ip.gif' width='13' height='15'> $ip <a href='/blog_article/$PHP_SELF/del/1/amp;time/$time.html'><img src='/image/del.gif' width='16' height='16' border=0></a></td> </tr> <tr>";
echo "<td colspan='5' height='33'>标题:$title</td> </tr>";
echo "<tr bgcolor='#ffffff'><td colspan='5' height='37'>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>
<?php
session_start();
if(!session_is_registered("superlogin"))//检查是否注册
{
echo "<a href='/superadmin.html'>请重新进行管理员登陆<BR>";
exit;
}
include ("../config.php");
if($del==1){ //判断是否要删除
mysql_query("delete from notebook where time='$time'",$db); //以留言时间为删除标志
echo "删除成功!";
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>删除留言</TITLE>
<style type="text/css">
<!--
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
$result = mysql_query("SELECT * FROM notebook",$db);
$row=mysql_num_rows($result);//查看结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){$page=1;}
$p=ceil($max/10);
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);} else {$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebook ORDER BY time DESC limit $low,$x",$db);
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><img src="/image/classlogo.gif" width="224" height="60" border="0"></td>
<td height="62" width="66%">
<div align="center"><img src="/image/note.gif" width="410" height="60"><img src="/image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="28%" ><a href="/guest.html" >首页</a>
> <a href="/blog_article/index.html" >留言簿</a></td>
<td width="56%" >
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n++){
echo "<a href=/blog_article/index/page/$n/gt;$n/lt;/a/gt;.html";
}
echo "页";
?>
</td>
<td width="16%"><a href="/blog_article/index.html" >查看留言</a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i++) {
$user=mysql_result($result,$i,'user');
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
$yresult = mysql_query("SELECT * FROM user where user='$user'",$db);//读取成员数据库
$name=mysql_result($yresult,0,'name');
$signature=mysql_result($yresult,0,'signature');//读取个人签名
$email=mysql_result($yresult,0,'email');
$face=mysql_result($yresult,0,'face');
$face='../image/face/icon'.$face;
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height=107' bordercolor='#FFFFFF'> <tr bgcolor='#eeeeee'>";
echo "<td width='10%' height='33' bgcolor='#eeeeee' > <img src='/blog_article/$face.gif' width='32' height='32'></td>";
echo "<td width='16%' height='33' bgcolor='#eeeeee' >留言人:$name</td>";
echo "<td width='41%' height='33' bgcolor='#eeeeee' >发表于:$time</td>";
echo "<td width='12%' height='33' bgcolor='#eeeeee' ><a href='mailto:$email'><img src='/image/email.gif' width='16' height='16' border=0></a></td>";
echo "<td width='21%' height='33' ><img src='/image/ip.gif' width='13' height='15'> $ip <a href='/blog_article/$PHP_SELF/del/1/amp;time/$time.html'><img src='/image/del.gif' width='16' height='16' border=0></a></td> </tr> <tr>";
echo "<td colspan='5' height='33'>标题:$title</td> </tr>";
echo "<tr bgcolor='#ffffff'><td colspan='5' height='37'>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>
客人留言簿管理: class/notebookg/delnote.php
<?php
session_start();
if(!session_is_registered("superlogin"))//检查是否注册
{
echo "<a href='/superadmin.html'>请重新进行管理员登陆<BR>";
exit;
}
include ("../config.php");
if($del==1){ //判断是否要删除
mysql_query("delete from notebookg where time='$time'",$db); //以留言时间为删除标志
echo "删除成功!";
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>删除留言</TITLE>
<style type="text/css">
<!--
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
$result = mysql_query("SELECT * FROM notebookg ",$db);
$row=mysql_num_rows($result);//查看结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){$page=1;}
$p=ceil($max/10);
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);} else {$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebookg ORDER BY time DESC limit $low,$x",$db);
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><img src="/image/classlogo.gif" width="224" height="60" border="0"></td>
<td height="62" width="66%">
<div align="center"><img src="/image/note.gif" width="410" height="60"><img src="/image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="28%" ><a href="/guest.html" >首页</a>
> <a href="/blog_article/index.html" >留言簿</a></td>
<td width="56%" >
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n++){
echo "<a href=/blog_article/index/page/$n/gt;$n/lt;/a/gt;.html";
}
echo "页";
?>
</td>
<td width="16%"><a href="/blog_article/index.html" >查看留言</a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i++) {
$email=mysql_result($result,$i,'email');
$face=mysql_result($result,$i,'face');
$face='../image/face/icon'.$face;
$name=mysql_result($result,$i,'name');
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height=107' bordercolor='#FFFFFF'> <tr bgcolor='#eeeeee'>";
echo "<td width='10%' height='33' bgcolor='#eeeeee' > <img src='/blog_article/$face.gif' width='32' height='32'></td>";
echo "<td width='16%' height='33' bgcolor='#eeeeee' >留言人:$name</td>";
echo "<td width='41%' height='33' bgcolor='#eeeeee' >发表于:$time</td>";
echo "<td width='12%' height='33' bgcolor='#eeeeee' ><a href='mailto:$email'><img src='/image/email.gif' width='16' height='16' border=0></a></td>";
echo "<td width='21%' height='33' ><img src='/image/ip.gif' width='13' height='15'> $ip <a href='/blog_article/$PHP_SELF/del/1/amp;time/$time.html'><img src='/image/del.gif' width='16' height='16' border=0></a></td> </tr> <tr>";
echo "<td colspan='5' height='33'>标题:$title</td> </tr>";
echo "<tr bgcolor='#ffffff'><td colspan='5' height='37'>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>
最新技术文章: