php+mysql写的简单留言本实例代码
发布时间:2020-12-13 05:26:15 所属栏目:PHP教程 来源:网络整理
导读:guestbook.php: metahttp-equiv="Content-Language"c metahttp-equiv="Content-Type"c divalign="center" tableborder="0"cellpadding="0"cellspacing="0"width="574"height="312" tr tdpalign="center"高三 班留言本本 /td /tr tr tdwidth="574"height="272
guestbook.php: <metahttp-equiv="Content-Language"c> <metahttp-equiv="Content-Type"c> <divalign="center"> <tableborder="0"cellpadding="0"cellspacing="0"width="574"height="312"> <tr> <td><palign="center">高三<6>班留言本本</td> </tr> <tr> <tdwidth="574"height="272"valign="top"> <formmethod="POST"action="ly.php"> <tableborder="0"cellpadding="0"cellspacing="0"width="100%"> <tr> <tdwidth="26%"align="right"> 姓名:</td> <tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999" type="text"name="T1"size="13"></td> </tr> <tr> <tdwidth="26%"align="right"> EMAIL:</td> <tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T2"size="13"></td> </tr> <tr> <tdwidth="26%"align="right"> 个人主页:</td> <tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T3"size="13"value="http://";></td> </tr> <tr> <tdwidth="26%"align="right"> 主题:</td> <tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T4"size="13"></td> </tr> <tr> <tdwidth="26%"align="right"valign="top"> 留言:</td> <tdwidth="74%"><textareastyle="font-size:9pt;width:313;background-color:#f8f8f8;height:177;border:1pxsolid#9a9999"rows="10"name="S1"cols="45"></td> </tr> <tr> <tdwidth="100%"align="right"colspan="2"> </td> </tr> </table> <palign="center"> <inputtype="submit"value="提交"name="B1"><inputtype="reset"value="重写"name="B2"> </td> </tr> </table> <hrsize='1'color='#6666FF'> <divalign="center"> <tableborder="0"cellpadding="0"cellspacing="0"width="603"height="294"> <tr> <tdwidth="603"height="294"> <? include("connect.rec"); $qh=mysql_query("SELECTCOUNT()ASrcntFROMguestbook"); $data=mysql_fetch_array($qh); $nr=$data["rcnt"]; //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0 if(empty($offset)) { $offset=0; } //查询结果(这里是每页20条,但你自己完全可以改变它) //$result=mysql_query("SELECTfromguestbookORDERBYtimedescLIMIT$offset,5"); $result=mysql_query("SELECTfromguestbookLIMIT$offset,5"); //显示返回的5条记录 while($data=mysql_fetch_array($result)) { printf("姓名:<fontcolor='#000000'>%s ",$data["name"]); printf("EMAIL:<fontcolor='#3366FF'>%s ",$data["mail"]); printf("个人主页:<fontcolor='#3366FF'>%s ",$data["url"]); printf("来自:<fontcolor='#3366FF'>%s ",$data["ip"]); printf("留言时间:<fontcolor='#3366FF'>%s ",$data["time"]); printf("主题:<fontcolor='#3366FF'>%s ",$data["title"]); printf("内容:<fontcolor='#000000'>%s ",$data["ly"]); printf("<hrsize='1'color='#6666FF'>"); } //下一步,要写出到其它页面的链接 if($offset)//如果偏移量是0,不显示前一页的链接 { $preoffset=$offset-5; print"<ahref="$PHP_SELF?offset=$preoffset">前一页n"; } //计算总共需要的页数 $pages=ceil($nr/5);//$pages变量现在包含所需的页数 for($i=1;$i<=$pages;$i++) { $newoffset=5$i-5; print"<ahref="$PHP_SELF?offset=$newoffset">$in"; } //检查是否是最后一页 $next=$offset+5; if($next<$nr) { print"<ahref="$PHP_SELF?offset=$next">下一页n"; } printf("<ahref='javascript:history.back()'>返回") ?> </td> </tr> </table> |