| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> mysql >> ru he yong PHP he mysql chuang jian yi ge ShoutBox

ru he yong PHP he mysql chuang jian yi ge ShoutBox

2008-12-22 08:10:14 编辑來源:互联网 评论
 
 
 
本文为【如何用PHP和mysql创建一个ShoutBox】的拼音翻译版
  zuo wei yi ge PHP kai fa ren yuan , wo you shi bei yao qiu zuo ge shoutbox 。 ru guo tong yang de shi qing ye fa sheng zai ni shen shang , zhe li you yi ge kuai su zhi nan 。 xian ran , nin yao wei ta tian jia nin zi ji de CSS zai shang mian , dan zhe li shi ji ben si lu 。
  wo men xu yao yi ge MySQL shu ju ku biao he san ge PHP wen jian 。
  shou xian , wo men xu yao yi ge wen jian bao cun shu ju ku xin xi
  --- wen jian #1:mysql.inc.php---
  <?php
  # Simply Shouting - ashoutboxexample
  # File name:mysql.inc.php
  # Description: A file to hold database info.
  $host ='localhost';
  $user ='database_user_name';
  $password='database_user_password';
  $name ='database_name';
  ?>
  chuang jian yi ge you si ge zi duan de shu ju biao . wo men ming ming wei shouts. ci qian ke neng ni mei you zhe ge SQL wen jian , chuang jian yi ge PHP wen jian "install.php". zhe ge wen jian yong guo yi ci zhi hou , ji de yao shan chu ta !
  -- wen jian #2: install.php--
  <?php
  # Simply Shouting - ashoutboxexample
  # File name: install.php
  # Description: Creates the database table.
  // include the database info file
  include("mysql.inc.php");
  // lian jie shu ju ku
  $connection= @mysql_connect($host,$user,$password) or die(mysql_error());
  $db= @mysql_select_db($name,$connection) or die(mysql_error());
  // ru guo wo men yi jing you yi ge biao ming zi jiao zuo "shouts", xu yao xian shan chu ta
  $sql='DROP TABLE IF EXISTS `shouts`';
  $result= @mysql_query($sql,$connection) or die(mysql_error());
  // xian zai que ding mei you xiang tong ming zi de biao , chuang jian ta
  $sql='CREATE TABLE `shouts` (
  `id` int(11) NOT NULL auto_increment,
  `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `shoutby` varchar(50) default NULL,
  `shout` varchar(50) default NULL,
  PRIMARY KEY `id` (`id`)
  ) TYPE=MyISAM AUTO_INCREMENT=1';
  echo'Creating table: \'shouts\'....';
  // guan bi lian jie
  $result= @mysql_query($sql,$connection) or die(mysql_error());?>
  <html>
  <head>
  <title>Simply Shouting - an zhuang </title>
  </head>
  <body>
  <br />
  ni de an zhuang guo cheng yi jing wan cheng . qing li ji cong ni de fu wu qi shang shan chu suo you an zhuang wen jian . ben cheng xu bao han yi xia an zhuang wen jian :<br />
  <br />
  1) install.php<br />
  <br />
  <br />
  <!-- I could just send them to index.phpautomatically, but then they'd wonder if it created correctly or not. -->
  dian ji <a href="index.php"> zhe li </a> kai shi .</html>
  zhe shi zhu wen jian :
  --- wen jian #3: index.php---
  <?
  # Simply Shouting - ashoutboxexample
  # File name: index.php
  # Description: Main page to display our shouts.
  // bao han shu ju ku xin xi
  include_once("mysql.inc.php");
  // lian jie shu ju ku
  $connection= @mysql_connect($host,$user,$password) or die(mysql_error());
  $db= @mysql_select_db($name,$connection) or die(mysql_error());
  ?>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">
  <!--
  body,td,th {
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
  }
  -->
  </style><body>
  <div style="width:500px;height 400px; border:thin groove #519554;">
  <?
  // xian shi zui xin 10 tiao liu yan . shou xian , chu shi hua yi ge ji shu qi
  $counting=0;
  // we need a counter because I want to show our shouts in ASC order
  // (like a chat room)
  $sql=mysql_query("SELECT * FROM `shouts`");
  while($data=mysql_fetch_array($sql)){
  //counts every row
  $counting=$counting+1;
  } //end while
  // if the count comes back greater than 10, then we select the last
  // 10 shouts for display.
  if($counting>10){
  $countlessten=$counting-9;
  $sql=mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT $countlessten,10");
  }else{
  //else it doesn't matter, there's less than 10!
  $sql=mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT 10");
  }
  while($data=mysql_fetch_array($sql)){
  //my timestamp field in the database is basically useless to me unless
  //I parse it. The following code parses the timestamp into things I
  //can use.
  $timestamp=$data['timestamp'];
  $postedyear=substr($timestamp,0,4);
  $postedmonth=substr($timestamp,5,2);
  $postedday=substr($timestamp,8,2);
  $postedtime=substr($timestamp,11,5);
  $newpostedtime="";
  $nomilitary=substr($postedtime,0,2);
  // the hour is greater than 12, so we need to switch back to 1-12 and
  // add a "pm"
  if($nomilitary>=13){
   $nomilitary=$nomilitary-12;
   $newpostedtime=$nomilitary;
   $newpostedtime.=":";
   $newpostedtime.=substr($postedtime,3,2) ;
   $newpostedtime.=" pm";
  }
  if($newpostedtime!=""){
   $postedtime=$newpostedtime;
  }else{
   $postedtime.=" am";
  }
  //now that we have the time, let's get the shout and the shouter
  $shoutby=$data['shoutby'];
  $shout=$data['shout'];
  echo$postedmonth."/".$postedday."/".$postedyear." at ".$postedtime." - <strong>".$shoutby." said: </strong>".$shout."<br><br>";
  // looks like: 12/1/2008 at 5:02pm - Josh said: Yo Yo Yo!
  }
  //below is the HTML form for creating the shouts
  ?>
  <form id="newshout" name="newshout" action="newshout.php" method="post"><input name="shoutby" type="text" id="shoutby" onClick="javascript:this.value=''" value="Enter your name here" size="24" maxlength="50" />
  <br><br><input name="shout" type="text" id="shout" onClick="javascript:this.value=''" value="Click & Shout!" size="24" maxlength="50" />
  <br><br><input id="submit" name="submit" type="submit" value="Shout!" /></form>
  </div>
  </body>
  </html>
  zui hou , wo men xu yao yi ge PHP wen jian chu li biao dan .
  -- wen jian #4: newshout.php--
  <?
  # Simply Shouting - ashoutboxexample
  # File name: newshout.php
  # Description: Process the HTML form on index.phpand redirect.
  // de dao liu yan zhe xing ming
  $shoutby=$_POST['shoutby'];
  if($shoutby=="Enter your name here"||$shoutby==""){
  // ru guo mei you shu ru ming zi
  $shoutby="Visitor";
  }
  if($_POST['shout']){
  // liu yan xin xi
  if($_POST['shout'] !="Click & Shout!"){
   //they didn't shout the default, so continue processing
   $shout=$_POST['shout'];
   // ti huan diao "<" he ">" yi zu zhi hei ke
   $shout=str_replace("<"," ",$shout);
   $shout=str_replace(">"," ",$shout);
   // bao han shu ju xin xi
   include_once("dbaccess.php");
  
   // lian jie shu ju ku
   $connection= @mysql_connect($host,$user,$password) or die(mysql_error());
   $db= @mysql_select_db($name,$connection) or die(mysql_error());
  
   // cha ru liu yan xin xi dao shu ju ku
   $sql="INSERT INTO `shouts`(`shoutby`,`shout`) VALUES('$shoutby','$shout')";
  // guan bi lian jie
  $result= @mysql_query($sql,$connection);
  }
  }
  ?>
  <html>
  <head>
  </head>
  <body onLoad="window.open('index.php','_self')">
  </body>
  </html>【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
zuo wei yi ge PHP kai fa ren yuan , wo you shi bei yao qiu zuo ge shoutbox 。 ru guo tong yang de shi qing ye fa sheng zai ni shen shang , zhe li you yi ge kuai su zhi nan 。 xian ran , nin yao wei ta tian jia nin zi ji de CSS zai shang mian , dan zhe li shi ji ben si lu 。 wo men xu yao yi ge MySQL shu ju ku biao he san ge PHP wen jian 。 shou xian , wo men xu yao yi ge wen jian bao cun shu ju ku xin xi --- wen jian #1:mysql.inc.php--- <?php # Simply Shouting - ashoutboxexample # File name:mysql.inc.php # Description: A file to hold database info. $host ='localhost'; $user ='database_user_name'; $password='database_user_password'; $name ='database_name'; ?> chuang jian yi ge you si ge zi duan de shu ju biao . wo men ming ming wei shouts. ci qian ke neng ni mei you zhe ge SQL wen jian , chuang jian yi ge PHP wen jian "install.php". zhe ge wen jian yong guo yi ci zhi hou , ji de yao shan chu ta ! -- wen jian #2: install.php-- <?php # Simply Shouting - ashoutboxexample # File name: install.php # Description: Creates the database table. // include the database info file include("mysql.inc.php"); // lian jie shu ju ku $connection= @mysql_connect($host,$user,$password) or die(mysql_error()); $db= @mysql_select_db($name,$connection) or die(mysql_error()); // ru guo wo men yi jing you yi ge biao ming zi jiao zuo "shouts", xu yao xian shan chu ta $sql='DROP TABLE IF EXISTS `shouts`'; $result= @mysql_query($sql,$connection) or die(mysql_error()); // xian zai que ding mei you xiang tong ming zi de biao , chuang jian ta $sql='CREATE TABLE `shouts` ( `id` int(11) NOT NULL auto_increment, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `shoutby` varchar(50) default NULL, `shout` varchar(50) default NULL, PRIMARY KEY `id` (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1'; echo'Creating table: \'shouts\'....'; // guan bi lian jie $result= @mysql_query($sql,$connection) or die(mysql_error());?> <html> <head> <title>Simply Shouting - an zhuang </title> </head> <body> <br /> ni de an zhuang guo cheng yi jing wan cheng . qing li ji cong ni de fu wu qi shang shan chu suo you an zhuang wen jian . ben cheng xu bao han yi xia an zhuang wen jian :<br /> <br /> 1) install.php<br /> <br /> <br /> <!-- I could just send them to index.phpautomatically, but then they'd wonder if it created correctly or not. --> dian ji <a href="index.php"> zhe li </a> kai shi .</html> zhe shi zhu wen jian : --- wen jian #3: index.php--- <? # Simply Shouting - ashoutboxexample # File name: index.php # Description: Main page to display our shouts. // bao han shu ju ku xin xi include_once("mysql.inc.php"); // lian jie shu ju ku $connection= @mysql_connect($host,$user,$password) or die(mysql_error()); $db= @mysql_select_db($name,$connection) or die(mysql_error()); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css"> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style><body> <div style="width:500px;height 400px; border:thin groove #519554;"> <? // xian shi zui xin 10 tiao liu yan . shou xian , chu shi hua yi ge ji shu qi $counting=0; // we need a counter because I want to show our shouts in ASC order // (like a chat room) $sql=mysql_query("SELECT * FROM `shouts`"); while($data=mysql_fetch_array($sql)){ //counts every row $counting=$counting+1; } //end while // if the count comes back greater than 10, then we select the last // 10 shouts for display. if($counting>10){ $countlessten=$counting-9; $sql=mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT $countlessten,10"); }else{ //else it doesn't matter, there's less than 10! $sql=mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT 10"); } while($data=mysql_fetch_array($sql)){ //my timestamp field in the database is basically useless to me unless //I parse it. The following code parses the timestamp into things I //can use. $timestamp=$data['timestamp']; $postedyear=substr($timestamp,0,4); $postedmonth=substr($timestamp,5,2); $postedday=substr($timestamp,8,2); $postedtime=substr($timestamp,11,5); $newpostedtime=""; $nomilitary=substr($postedtime,0,2); // the hour is greater than 12, so we need to switch back to 1-12 and // add a "pm" if($nomilitary>=13){ $nomilitary=$nomilitary-12; $newpostedtime=$nomilitary; $newpostedtime.=":"; $newpostedtime.=substr($postedtime,3,2) ; $newpostedtime.=" pm"; } if($newpostedtime!=""){ $postedtime=$newpostedtime; }else{ $postedtime.=" am"; } //now that we have the time, let's get the shout and the shouter $shoutby=$data['shoutby']; $shout=$data['shout']; echo$postedmonth."/".$postedday."/".$postedyear." at ".$postedtime." - <strong>".$shoutby." said: </strong>".$shout."<br><br>"; // looks like: 12/1/2008 at 5:02pm - Josh said: Yo Yo Yo! } //below is the HTML form for creating the shouts ?> <form id="newshout" name="newshout" action="newshout.php" method="post"><input name="shoutby" type="text" id="shoutby" onClick="javascript:this.value=''" value="Enter your name here" size="24" maxlength="50" /> <br><br><input name="shout" type="text" id="shout" onClick="javascript:this.value=''" value="Click & Shout!" size="24" maxlength="50" /> <br><br><input id="submit" name="submit" type="submit" value="Shout!" /></form> </div> </body> </html> zui hou , wo men xu yao yi ge PHP wen jian chu li biao dan . -- wen jian #4: newshout.php-- <? # Simply Shouting - ashoutboxexample # File name: newshout.php # Description: Process the HTML form on index.phpand redirect. // de dao liu yan zhe xing ming $shoutby=$_POST['shoutby']; if($shoutby=="Enter your name here"||$shoutby==""){ // ru guo mei you shu ru ming zi $shoutby="Visitor"; } if($_POST['shout']){ // liu yan xin xi if($_POST['shout'] !="Click & Shout!"){ //they didn't shout the default, so continue processing $shout=$_POST['shout']; // ti huan diao "<" he ">" yi zu zhi hei ke $shout=str_replace("<"," ",$shout); $shout=str_replace(">"," ",$shout); // bao han shu ju xin xi include_once("dbaccess.php"); // lian jie shu ju ku $connection= @mysql_connect($host,$user,$password) or die(mysql_error()); $db= @mysql_select_db($name,$connection) or die(mysql_error()); // cha ru liu yan xin xi dao shu ju ku $sql="INSERT INTO `shouts`(`shoutby`,`shout`) VALUES('$shoutby','$shout')"; // guan bi lian jie $result= @mysql_query($sql,$connection); } } ?> <html> <head> </head> <body onLoad="window.open('index.php','_self')"> </body> </html>
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
情人节的清纯女生(9)
情人节的清纯女生(8)
情人节的清纯女生(7)
情人节的清纯女生(6)
山东蓬莱海边组照
一探哲蚌 II
一探哲蚌 III
古长城的一角
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有