zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

PHP+MYSQL的文章管理系统(二)

2023-06-13 09:13:43 时间
###############index.php######################
<?session_start();
require"./inc/func.php";
mscon();
require"./inc/header.inc";
?>
<scriptlanguage="javascript">
functionopwin(filename)
{                window.open("read_article.php?id="+filename,"","height=500,width=585,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
        }

</script>
</head>
<bodybgcolor="#FFFFFF"text="#000000"leftmargin="0"topmargin="0">
<tablewidth="100%"border="0"cellspacing="0"cellpadding="0"bgcolor="#003399"height="23">
  <tr>
    <tdwidth="80">
      <divid="Layer2"style="position:absolute;left:7px;top:17px;width:43px;height:44px;z-index:2"><objectclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"width="80"height="60">
          <paramname=movievalue="images/logo.swf">
          <paramname=qualityvalue=high>
          <paramname="wmode"value="transparent">
          <embedsrc="images/logo.swf"quality=highpluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"type="application/x-shockwave-flash"width="80"height="60"wmode="transparent">
          </embed>
        </object></div>
      <divid="Layer1"style="position:absolute;left:-5px;top:61px;width:49px;height:37px;z-index:1"><imgsrc="images/11.gif"width="58"height="55"></div>
    </td>
    <tdwidth="539"><objectclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"width="468"height="60">
          <paramname=movievalue="images/ti1.swf">
          <paramname=qualityvalue=high>
          <paramname="wmode"value="transparent">
          <embedsrc="images/ti1.swf"quality=highpluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"type="application/x-shockwave-flash"width="468"height="60"wmode="transparent">
          </embed>

      </object></td>
  </tr>
</table>
<tablewidth="100%"border="0"cellspacing="0"cellpadding="0">
  <tr>
    <tdbackground="images/211.gif"height="2"> </td>
  </tr>
</table>
<table><FORMname=form1action=search.php  method=posttarget=_blank>
  <tablewidth="80%"border="0"cellspacing="0"cellpadding="0"bgcolor="#009933"align="center">
    <tr>
    <tdalign="center">
    <inputtype="text"name="key">
  <selectname="type">
  <optionvalue=>全部类别</option>
<?$typ=file("list.txt");
$num=count($typ);
for($i=2;$i<=$num;$i++)
{
  echo"<optionvalue=$typ[$i]>$typ[$i]</option>";}
      ?>
  </select>
  <selectname="whe">
  <optionvalue=>全部内容</option>
  <optionvalue=1>文章内容</option>
  <optionvalue=2>文章标题</option>
  <optionvalue=3>加入时间</option>
  </select>
  <inputtype="hidden"name="submit"value="1">
  <inputtype="submit"name="submit"value="提交查询">
  </td>
  </tr>
</table>
</FORM></table>
<?
$type=trim($type);
  if($comm)
    {
     $sec="andcomm=1";
     $fir="wherecomm=1";
    }
  if(!empty($type))
    $query="selectcount(*)from$tablewheretype="$type"$sec";
  else
    $query="selectcount(*)from$table$fir";
  $res=mysql_db_query("$database",$query);
  if(@mysql_num_rows($res)>0)
    $tot=mysql_fetch_array($res);
  $total=$tot[0];
  $total_page=ceil($total/$pagenum);
  echo"<tablewidth="80%"border="0"cellspacing="0"cellpadding="0"align=center>";
  echo"<tr><td>共:".$total."篇".$total_page."页</td></tr>";
  if(empty($page))
    $page=0;
  if(empty($offset))
    $offset=0;
  $offset=$pagenum*$page;
  if(!empty($type))
     $query="select*from$tablewheretype="$type"$secorderbyiddesclimit$offset,$pagenum";
  else
    $query="select*from$table$firorderbyiddesclimit$offset,$pagenum";
  $res=mysql_db_query("$database",$query);
  if(@mysql_num_rows($res)>0)
     while($topic=mysql_fetch_array($res))
       {
         if(strlen($topic[title])>40)
          {
            $topic[title]=substr($topic[title],0,40);
            $topic[title]=$topic[title].".....";
          }
         if(trim($topic[time])==date(Y年m月d日))
           $topic[time]="<fontcolor=#FF9900>$topic[time]</font>";
           echo"<tr><td>[$topic[type]]<ahref=#onClick="opwin($topic[id])";>$topic[title]</a><fontsize=1>($topic[time])</font>";
        if($topic[comm]==1)
          echo"<imgsrc="./images/comm.gif"alt="精品文章">";
        if($topic[locked]==1)
          echo"<imgsrc="./images/locked.gif"alt="文章已锁定">";
        echo"</td>
          <td>阅读:$topic[hits]次;评论:$topic[p_num]次</td>
          </tr>";
     }
else
   echo"对不起,本栏目暂没有任何文章!!!";
echo"</table>";
  ?>

<br>
<tablewidth="80%"border="0"cellspacing="0"cellpadding="0"align="center">
  <tr>
    <td>
  <?
     $pre=$page-1;
     $next=$page+1;
if($page>0)
   echo"<ahref="$php_self?page=$pre&type=$type">上一页</a><br><br>";
else
  echo"上一页<br><br>";  ?></td>
    <td><?if($page<$total_page-1)
   echo"   <ahref="$php_self?page=$next&type=$type">下一页</a><br><br>";
elseecho"   下一页<br><br>";?></td>
    <td>
<form>跳转到:
        <selectname="page"onchange="top.location="<?echo$php_self;?>?page="+document.forms[1].elements[0].value+"&type=<?echo$type;?>";"class="border">
          <?
  for($i=0;$i<$total_page;$i++)
    {
     $p=$i+1;
     echo"<optionvalue=$i";
     if($page==$i)echo"selected";
     echo">第".$p."页</option>n";
     }
?>
        </select></form>
</td>
<td>
<form>选择栏目:
        <selectname="type"  onchange="top.location="<?echo$php_self;?>?type="+document.forms[2].elements[0].value<?if($comm)echo"+"&comm=1"";?>;">
          <?$typ=file("list.txt");
$num=count($typ);
for($i=0;$i<$num;$i++)
{
  echo"<optionvalue=$typ[$i]";if(trim($typ[$i])==$type){  echo"  selected";}echo">$typ[$i]</option>";}
      ?>
        </select>
    </form>
</td><td><formmethod="post"action=<?echo$PHP_SELF;?>?type=<?echo$type;?>target="_balnk"><inputtype="submit"name="comm"value="精品文章"class=border></form></td>
</tr>
</table>
<?require"./inc/footer.inc";?>
#####################read_article.php#########################
<?
require"./inc/func.php";
if(!$id)
{
  echo"<script>window.close();</script>";
   exit();
}
mscon();
$query="select*from$tablewhereid="$id"";
$res=mysql_db_query("$database",$query);
if(!$res)
  {
    echo"thisarticlehasbeendeletedornothisarticle!!";
    exit();
  }
$data=mysql_fetch_array($res);
add_hits($data[id]);
$pre=$data[id]-1;
$next=$data[id]+1;
?>
<HTML>
<HEAD>
<TITLE>
<?   echo"$data[title]--[$data[type]]";?>
</TITLE>
<METAhttp-equiv=Content-Typecontent="text/html;charset=gb2312">
<styletype=text/css>
<!--
body,table,td,input,textarea{  font-family:"宋体";font-size:9pt}
select{  font-family:"宋体";font-size:9pt}
code{font-family:"Courier";font-size:10pt}
a{  color:#005500}
a:hover{  color:#CC0000}
.border{border:1px#000000solid;background-color:transparent;list-style-position:inside;list-style-type:square}
-->
</style>
<scriptlanguage="javascript">
functionname()
{
  vartheResult=true;
  varelem4=null;

  if(document.forms[0].elements[0].value==""||document.forms[0].elements[0].value=="undefined"||document.forms[0].elements[0].value=="null")
  {
    elem4=prompt("请输入您的姓名:","");
    theResult=false;
    document.forms[0].elements[0].value=elem4;
  }
  returntheResult;
}
functionmail()
{
  vartheResult=true;
  varelem1=null
  if((document.forms[0].elements[1].value.indexOf("@")==-1||document.forms[0].elements[1].value==""||document.forms[0].elements[1].value.indexOf(".")==-1))
  {
    elem1=prompt("请输入您的正确的电子邮件地址。谢谢!!","");
    theResult=false;
    document.forms[0].elements[1].value=elem1;
  }
  returntheResult;
}
functiongo()
{
vartheResult=true;
theResult=name()&&mail();
returntheResult;
}
</script>
</HEAD>
<BODYtext=#000000bgColor=#ffffff>
<TABLEborderColor=#339933cellSpacing=0borderColorDark=#ffffff
cellPadding=0align=centerborderColorLight=#000000border=1width=545>
  <TBODY>
  <TRvAlign=centerbgColor=#009900>
    <TDbackground=images/third-back3.gif>
      <TABLEcellSpacing=0cellPadding=0width=100%border=0>
        <TBODY>
        <TR>
          <TDwidth=17> </TD>
          <TDwidth=590>
            <TABLEwidth="36%"align=centerborder=0>
              <TBODY>
              <TR>
                <TDbgcolor="#009900">
                  <DIValign=center><FONTface="Verdana,Arial,Helvetica,sans-serif"color=#ffffff><b>
                    <?echo$data[title];?>
                    </b></FONT></DIV>
                </TD></TR></TBODY></TABLE></TD>
          <TDwidth=19>
            <DIValign=center><Ahref="javascript:window.close()"><IMGheight=17
            src="images/third-close.gif"width=17align=absMiddle
            border=0name=content_r03_c28></A></DIV>
          </TD></TR></TBODY></TABLE></TD></TR>
  <TRvAlign=centeralign=leftbgColor=#cccccc>
    <TD>
      <TABLEcellSpacing=0cellPadding=0border=0align="center"width="100%">
        <TBODY>
        <TR>
          <TD>
            <DIValign=left><Aclass=whitetxt
            href="read_article.php?id=<?echo  $pre;?>"><imgsrc="images/prethread.gif"width="48"height="12"border="0"></A></DIV>
          </TD>
          <TD>
            <DIValign=left><aclass=whitetxt
            href="read_article.php?id=<?echo$next;?>"><imgsrc="images/nextthread.gif"width="48"height="12"border="0"></a></DIV>
          </TD>
          <TD><IMG
            height=16src="images/mail.gif"width=16></TD>
          <TDclass=myfont><Aclass=redtxt
            href="commend.php?id=<?echo"$data[id]&title=$data[title]";?>">推荐给朋友</A></TD>
          <TD>发表时间:
            <?echo$data[time];?>
            阅读次数:
            <?echo$data[hits];?>
          </TD>
          <TD> </TD>
        </TR>
        </TBODY>
      </TABLE>
    </TD></TR>
    <TRvAlign=top>
    <TDclass=tenpt>
<?
if($data[locked]<>0)
{
  echo"<imgsrc=images/lock.gif>对不起!本文已经被管理员锁定!";
}
else
  if($data[html]==1)
     highlight_string($data[cont]);
  else
     echonl2br($data[cont]);
?>
      </TD>
  </TR>
  </TBODY></TABLE>
<tablebordercolor=#339933cellspacing=0bordercolordark=#ffffff
cellpadding=0align=centerbordercolorlight=#000000border=1width=545>
  <tbody>
<TRbgColor=#cccccc>
    <th>
      <DIValign=center>发表评论</DIV>
    </th>
  </TR>
  <tr>
    <td>
<formname="form1"method="post"action="ping.php"onsubmit="returngo()">
        您的姓名:
        <inputtype="text"name="name"class="border">
         您的电子邮件:
        <inputtype="text"name="mail"size=20class="border">
        仅站长可见:<inputtype="checkbox"name="pub"value="<?echo$data[title];?>">
        <inputtype="hidden"name="p_id"value="<?echo$id;?>">
        <br>
        发表评论:
        <textareaname="cont"rows="8"cols="85"></textarea>
        <br>
        <br>
        <center>
          <inputtype="submit"name="Submit"value="提交"class="border">
          <inputtype="reset"name="Submit2"value="重写"class="border">
        </center></form>
        </td>
  </tr>
  <TRbgColor=#cccccc>
    <th>
      <DIValign=center>相关评论</DIV>
    </th>
  </TR>
  <tr>
  <td>
<?  $query="select*from$ping_tabwherep_id="$id"orderbytimedesc";
  $res=mysql_db_query("$database",$query);
  if(mysql_num_rows($res)>0)
   {$i=1;
   while($ping=mysql_fetch_array($res))
    echo"评论人:$ping[name]   电子邮件:$ping[mail]<br>  ".nl2br($ping[p_cont])."<br>时间:$ping[time]  来自:$ping[ip]<hrsize=1>n";
   }
   else
   echo"暂时没有本文章的相关评论!";
  ?>
  </td>
  </tr>
  <trbgcolor=#cccccc>
    <td>
      <divalign=center><a
  href="javascript:window.close()">关闭窗口</a></div>
    </td>
  </tr>
  </tbody>
</table>
<?require"./inc/footer.inc";?>