网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > PHP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.PHP反射机制实现动态代理的代码.
.最小化数据传输——在客户端存储.
.php代码优化及php相关问题总结.
.PHP的Socket函数参考.
.如何对PHP程序中的常见漏洞进行攻.
.不用GD库生成当前时间的PNG格式图.
.利用js调用后台php进行数据处理原.
.PHP has encountered an Access .
.使用PHP编写基于Web的文件管理系.
.解决RHAS3中Apache2的PHP上传文件.
.PHP5中PDO的简单使用.
.使用 php4 加速 web 传输 &.
.一个SQL管理员的web接口.
.[GD]生成bmp格式的图片(imagebmp).
.在字符串中把网址改成超级链接.
.动态新闻发布的实现及其技巧.
.PHP网站提速三大“软”招.
.对Javascript和select部件的结合.
.如何在PHP中进行身份认证.
.动态网页技术PHP关于cookie和ses.

多数据表共用一个页的新闻发布

发表日期:2001-6-11


本文为了简单并能够说明主要内容,一些次要的html内容相对简单。
在网站有多个内容要在某一页显示时可在网页中共用一个显示和提交。
本例中有两个数据表(news,ctm);一个主页(index.php);
一个提交页(index_pub.php;和一个包函页(index_view.php)
一个子页(view_d.php)。
----news,ctm---
increate table news(id int(80) not null auto_increment,title char(100),detail text,primay key(id));
increate table ctm(id int(80) not null auto_increment,title char(100),detail text,primay key(id));


----index_view.php---
<?ph
$query="select * from ".$name." order by id desc limit 0,5;
$result=mysql_query($query,$db);
if ($result){
while($myrow=msyql_fetch_array($result)){
?>
<tr><td><a href="view_d.php?recod=<?php echo $myrow[id]; ?>&name=<?php echo $name; ?>">$myrow[title]</a></td></tr>
<?php
  }
}
else{
echo "这里还没新的内容。";}
?>


----index.php---
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<hr size=0 color=green width=100%>
<p align=left><font color=green size=+3>Yourname Online</font></p>
<hr size=3 color=green width=100%>
<p align=left><font size=-1>你现在的位置-->首页</font></p>
<hr size=2 color=green width=100%>
<table width=100 border=0 cellpadding=0 cellspacing=0>
  <tr>
<!-- news -->
    <td width=50% align=left>
      <table width=100 border=0 cellpadding=0 cellspacing=0>
        <?php
           $name=news;
           include("index_view.php");
        ?>
      </table>
    </td>
<!-- ctm -->
    <td width=50% align=left>
      <table width=100 border=0 cellpadding=0 cellspacing=0>
        <?php
           $name=ctm;
           include("index_view.php");
        ?>
      </table>
    </td>
  </tr>
</table>
<hr size=0 width=100% color=green>
<p align=center><font size=-1>Copyrignt 1999…</font></P>
</body>
</html>

----index_pub.php---
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<form action=index_view.php method=post>
  <p>请选择数据库:<br>
  <select name=db_name size=1>
    <option value=news>news</option>
    <option value=ctm>ctm</option>
  </select></p>
  <p>标题:<br>
  <input type=text name=title size=20></p>
  <p>内容:<br>
  <textarea rows=6 cols=10 name=detail></textarea></p>
  <p><input type=submit value=submit></p>
</form>
<?php
switch ($db_name){
   case news:$name=news;
   break;
   case ctm:$name=ctm;
   break;
}
$query="insert into ".$name."(title,detail) values('$title','$detail');
$result=mysql_query($query,$db);
if ($result){echo "ok";}
else{echo "failed";}
?>
</body>
</html>

----view_d.php---
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<?php
if ($recod){
   $query="select * from ".$name." where id=".$recod;
   $result=mysql_query($query,$db);
   $title=mysql_result($result,0,title);
   $detail=mysql_result($result,0,detail);
   echo "<p>标题:".$title."</p>";
   echo "<p>内容:".$detail."</p>";
}
else{echo "此文件已被删除!";}
</body>
</html> 
上一篇:3种平台下安装php4经验点滴 人气:10255
下一篇:层叠菜单的动态生成 人气:14715
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐