[原创]出来乍到,发一个小小的帖子 |
我学PHP也不是很久,马马虎虎做些东西。最近我做了个计数器和留言本的程序,效果还可以,请大家发表一下意见:
计数器的:
<?php
include "dbconnect.php";
$dbh=mysql_connect($dbhost,$dblogin,$dbpassword);
mysql_select_db($db);
/*此处显示状态:最大ID*/
$query="select id from count";
$res=mysql_query($query);
$row = mysql_fetch_row($res);
/*此处显示状态:插入1*/
$row[0]=$row[0]+1;
$query2="update count set id='$row[0]'";
$res2=mysql_query($query2);
$query3="select id from count";
$res3=mysql_query($query3);
$row3 = mysql_fetch_row($res3);
$m5=($row3[0]-$row3[0]%10000)/10000;
$m4=($row3[0]-$m5*10000-$row3[0]%1000)/1000;
$m3=($row3[0]-$m5*10000-$m4*1000-$row3[0]%100)/100;
$m2=($row3[0]-$m5*10000-$m4*1000-$m3*100-$row3[0]%10)/10;
$m1=$row3[0]-$m5*10000-$m4*1000-$m3*100-$m2*10;
echo "<body background='p/bg.gif'><table border=0><tr><td colspan=6><center><font color=blue><b>Visited:</b></font></td><td><img src='p/".$m5.".gif' width=20 height=20><img src='p/".$m4.".gif' width=20 height=20><img src='p/".$m3.".gif' width=20 height=20><img src='p/".$m2.".gif' width=20 height=20><img src='p/".$m1.".gif' width=20 height=20></td><td><embed src='music/2.mp3' width=0 height=0 autostart=true></td></tr></table></body>";
mysql_close();
?>
其中0-9九张图片保存在P文件夹里。
留言本的:
<?php
include "dbconnect.php";
$dbh=mysql_connect($dbhost,$dblogin,$dbpassword);
mysql_select_db($db);
/*此处显示状态:插入IP地址/
$ip=$_SERVER["REMOTE_ADDR"];
$ipquery="insert into ip(ip) values('$ip')";
$ipres=mysql_query($ipquery);
/*此处显示状态:计数器中加1*/
$query="select id from count";
$res=mysql_query($query);
$row = mysql_fetch_row($res);
$row[0]=$row[0]+1;
$query2="update count set id='$row[0]'";
$res2=mysql_query($query2);
/*此处显示状态:计数器中加1后调用计数器值*/
$query3="select id from count";
$res3=mysql_query($query3);
$row3 = mysql_fetch_row($res3);
/*此处显示状态:根据计数器值来决定放歌*/
$song=$row[0]%3+1;
if($song==1) echo "<body background='p/bg.gif'><b>Here's the message in the table support!<a href='support.php'><img src='p/write.gif' ></a></b><font color=blue size=2>You are the <font color=red>".$row3[0]."</font> visitor!</font><embed src='music/".$song.".rm' autostart=true loop=-1 width=0,height=0></body>";
if($song==3) echo "<body background='p/bg.gif'><b>Here's the message in the table support!<a href='support.php'><img src='p/write.gif' ></a></b><font color=blue size=2>You are the <font color=red>".$row3[0]."</font> visitor!</font></body>";
if($song==2) echo "<body background='p/bg.gif'><b>Here's the message in the table support!<a href='support.php'><img src='p/write.gif' ></a></b><font color=blue size=2>You are the <font color=red>".$row3[0]."</font> visitor!</font><embed src='music/".$song.".mp3' autostart=true loop=-1 width=0,height=0></body>";
/*此处显示状态:留言内容*/
$query="select max(id) from support";
$res=mysql_query($query);
$row = mysql_fetch_row($res);
for($i=$row[0];$i>0;$i--){
$query2="select id,name,email,message,date from support where id='$i'";
$res2=mysql_query($query2);
$row=mysql_fetch_row($res2);
echo "<table><tr><td>ID:</td><td><font color=red>".$row[0]."</td></font></tr>";
echo "<tr><td>Name: </td><td><font color=red>".$row[1]."</td></font></tr>";
echo "<tr><td>Email: </td><td><font color=red>".$row[2]."</td></font></tr>";
echo "<tr><td>Message: </td><td><font color=blue size=3>".$row[3]."</td></font></tr>";
echo "<tr><td>Date: </td><td><font color=red>".$row[4]."</td></font></tr></table><img src='p/angel.gif' ><hr>";
}
mysql_close();
?>
|
|
|