快速业务通道

PHP新手上路(十一) 数据库链接

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-26
aster";
$html_mail = "no";

?>
<HTML>
<HEAD>
<TITLE><?php echo $page_title; ?></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000000">
<FONT FACE="Verdana" SIZE="-2">
<?

/* connect to the database */
mysql_pconnect("$host","$user","$password") or die("Can''t connect to the SQL-server");
mysql_select_db("$database");

/* action=view : retrieve data from the database and show it to the user */
if($action == "view") {

/* function for showing the data */
function search_it($name) {

/* some vars */
global $offset,$total,$lpp,$dir;
global $table,$html_mail,$admin_name,$admin_mail;

/* select the data to get out of the database */
$query = "SELECT name, email, job, comments FROM $table";
$result = mysql_query($query);
$total= mysql_numrows($result);

print "<CENTER><FONT FACE="Verdana" SIZE="-2"><A HREF="guestbook.php3?action=add" onMouseOver="window.status=''Add your name'';return true" onMouseOut="window.status='''';return true" TITLE="Add your name">加入留言</A></FONT></CENTER><br><br>";

if ($total== 0) {
print "<CENTER>此刻没人留言</CENTER><br><br>"; }

elseif ($total> 0) {

/* default */
$counter=0;
if ($dir=="") $dir="Next";
$lpp=5;
if ($offset==0) $offset=0;

if ($dir=="Next") {

if ($total > $lpp) {

$counter=$offset;
$offset =$lpp;
$num=$offset;

if ($num > $total) {
$num=$total; } }

else {
$num=$total; } }

elseif ($dir=="Previous") {

if ($total > $lpp) {
$offset-=$lpp;

if ($offset < 0) {
$offset=0; }

$counter=$offset-$lpp;

if ($counter < 0)
$counter=0;
$num=$counter $lpp; }

else {
$num=$total; } }

while ($counter < $num) {
$j=0;
$j=$counter 1;

/* now really grab the data */
$i1=mysql_result($result,$counter,"name");
$i2=mysql_result($result,$counter,"email");
$i3=mysql_result($result,$counter,"job");
$i4=mysql_result($result,$counter,"comments");

$i4 = stripslashes ("$i4");

/* print it in a nice layout */
print "<CENTER>n";
print "<TABLE WIDTH=400 BORDER=0 ALIGN=CENTER VALIGN=TOP><TR><TD><FONT FACE="Verdana" SIZE="-2">n";
print "<HR>n";
print "<BR><B>Name:</B> $i1n";
print "<BR><B>email:</B><A HREF="mailto:$i2" onMouseOver="window.status=''Email $i2'';return true" onMouseOut="window.status='''';return true" TITLE="Email $i2">$i2</A>n";
print "<BR><B>Job:</B> $i3n";
print "<BR><B>Comment:</B>n";
print "<BR>$i4n";
p

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号