首页 > 代码库 > PHP文章管理(2)

PHP文章管理(2)

##############index.php###################### 
<?session_start(); 
require"./inc/func.php"; 
mscon(); 
require "./inc/header.inc"; 
?> 
<script language="javascript"> 
function opwin(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> 
<body bgcolor="#FFFFFF"text="#000000" leftmargin="0" topmargin="0"> 
<table width="100%"border="0" cellspacing="0" cellpadding="0"bgcolor="#003399" height="23"> 
<tr> 
<td width="80"> 
<div id="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"> 
<param name=movievalue="http://www.mamicode.com/images/logo.swf"> 
<param name=quality value=http://www.mamicode.com/high>
<param name="wmode"value="http://www.mamicode.com/transparent"> 
<embed src="http://www.mamicode.com/images/logo.swf"quality=high pluginspage="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> 
<div id="Layer1"style="position:absolute; left:-5px; top:61px; width:49px; height:37px;z-index:1"><img src="http://www.mamicode.com/images/11.gif" width="58"height="55"></div> 
</td> 
<td width="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"> 
<param name=movievalue="http://www.mamicode.com/images/ti1.swf"> 
<param name=quality value=http://www.mamicode.com/high>
<param name="wmode"value="http://www.mamicode.com/transparent"> 
<embed src="http://www.mamicode.com/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> 
<table width="100%"border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td background="images/211.gif"height="2">&nbsp;</td> 
</tr> 
</table> 
<table><FORM name=form1action=search.php method=post target=_blank> 
<table width="80%"border="0" cellspacing="0" cellpadding="0"bgcolor="#009933" align="center"> 
<tr> 
<td align="center"> 
<input type="text"name="key"> 
<select name="type"> 
<option value=http://www.mamicode.com/>全部類別
<? $typ=file("list.txt"); 
$num=count($typ); 
for($i=2;$i<=$num;$i++) 

echo"<optionvalue=http://www.mamicode.com/$typ[$i]>$typ[$i]";} 
?> 
</select> 
<select name="whe"> 
<option value=http://www.mamicode.com/>全部內容
<option value=http://www.mamicode.com/1>文章內容
<option value=http://www.mamicode.com/2>文章標題
<option value=http://www.mamicode.com/3>加入時間
</select> 
<input type="hidden"name="submit" value="http://www.mamicode.com/1"> 
<input type="submit"name="submit" value="http://www.mamicode.com/提交查詢"> 
</td> 
</tr> 
</table> 
</FORM></table> 
<? 
$type=trim($type); 
if($comm) 

$sec="and comm=1"; 
$fir="where comm=1"; 

if(!empty($type)) 
$query="select count(*) from $table wheretype=‘$type‘ $sec"; 
else 
$query="select count(*) 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 "<table width="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 $table wheretype=‘$type‘ $sec order by id desc limit $offset,$pagenum";
else 
$query="select * from $table $fir order byid desc limit $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]]<a href=http://www.mamicode.com/#"opwin($topic[id])";>$topic[title]</a><fontsize=1>($topic[time])</font>"; 
if($topic[comm]==1) 
echo "<img src="http://www.mamicode.com/images/comm.gif"alt="精品文章">"; 
if($topic[locked]==1) 
echo "<imgsrc="http://www.mamicode.com/images/locked.gif" alt="文章已鎖定">"; 
echo "</td> 
<td>閱讀:$topic[hits]次;評論:$topic[p_num]次</td> 
</tr>"; 

else 
echo " 對不起,本欄 目暫沒有任何文章!!!"; 
echo "</table>"; 
?> 

<br> 
<table width="80%"border="0" cellspacing="0" cellpadding="0"align="center"> 
<tr> 
<td> 
<? 
$pre=$page-1; 
$next=$page+1; 
if($page>0) 
echo "<ahref="http://www.mamicode.com/$php_self?page=$pre&type=$type">上一頁</a><br><br>"; 
else 
echo "上一頁<br><br>";?></td> 
<td><?if($page<$total_page-1) 
echo " <ahref="http://www.mamicode.com/$php_self?page=$next&type=$type">下一頁</a><br><br>"; 
else echo " 下一頁<br><br>";?></td> 
<td> 
<form> 跳轉到: 
<select name="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 "<option value=http://www.mamicode.com/$i"; 
if($page==$i) echo " selected" ; 
echo ">第".$p."頁</option>n"; 

?> 
</select> </form> 
</td> 
<td> 
<form >選擇欄目: 
<select name="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"<option value=http://www.mamicode.com/$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"><input type="submit" name="comm"value="http://www.mamicode.com/精品文章"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 $table whereid=‘$id‘"; 
$res=mysql_db_query("$database",$query); 
if(!$res) 

echo "this article has been deleted or nothis article!!"; 
exit(); 

$data=http://www.mamicode.com/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> 
<META http-equiv=Content-Typecontent="text/html; charset=gb2312"> 
<style type=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 #000000 solid;background-color:transparent; list-style-position: inside; list-style-type:square} 
--> 
</style> 
<script language="javascript"> 
function name() 

var theResult = true; 
var elem4 = null; 

if (document.forms[0].elements[0].value =http://www.mamicode.com/="" || document.forms[0].elements[0].value =http://www.mamicode.com/="undefined" ||document.forms[0].elements[0].value =http://www.mamicode.com/="null") 

elem4 = prompt("請輸入您的姓名:",""); 
theResult = false; 
document.forms[0].elements[0].value = http://www.mamicode.com/elem4;

return theResult; 

function mail() 

var theResult = true; 
var elem1 = null 
if((document.forms[0].elements[1].value.indexOf(‘@‘) == -1 || document.forms[0].elements[1].value=http://www.mamicode.com/="" || document.forms[0].elements[1].value.indexOf(‘.‘) == -1)) 

elem1 = prompt("請輸入您的正確的電子郵件地址。謝謝!!",""); 
theResult = false; 
document.forms[0].elements[1].value = http://www.mamicode.com/elem1;

return theResult; 

function go() 

var theResult=true; 
theResult = name()&&mail(); 
return theResult; 

</script> 
</HEAD> 
<BODY text=#000000 bgColor=#ffffff> 
<TABLE borderColor=#339933 cellSpacing=0borderColorDark=#ffffff 
cellPadding=0 align=centerborderColorLight=#000000 border=1 width=545> 
<TBODY> 
<TR vAlign=center bgColor=#009900> 
<TD background=images/third-back3.gif> 
<TABLE cellSpacing=0 cellPadding=0 width=100%border=0> 
<TBODY> 
<TR> 
<TD width=17>&nbsp;</TD> 
<TD width=590> 
<TABLE width="36%" align=centerborder=0> 
<TBODY> 
<TR> 
<TD bgcolor="#009900"> 
<DIV align=center><FONTface="Verdana, Arial, Helvetica, sans-serif"color=#ffffff><b> 
<? echo $data[title];?> 
</b></FONT></DIV> 
</TD></TR></TBODY></TABLE></TD> 
<TD width=19> 
<DIV align=center><Ahref="javascript:window.close()"><IMG height=17 
src="http://www.mamicode.com/images/third-close.gif" width=17align=absMiddle 
border=0name=content_r03_c28></A></DIV> 
</TD></TR></TBODY></TABLE></TD></TR> 
<TR vAlign=center align=leftbgColor=#cccccc> 
<TD> 
<TABLE cellSpacing=0 cellPadding=0 border=0 align="center"width="100%"> 
<TBODY> 
<TR> 
<TD> 
<DIV align=left><A class="whitetxt" 
href="http://www.mamicode.com/read_article.php?id=<? echo"><img src="http://www.mamicode.com/images/prethread.gif"width="48" height="12"border="0"></A></DIV> 
</TD> 
<TD> 
<DIV align=left><a class="whitetxt" 
href="http://www.mamicode.com/read_article.php?id=<? echo"><img src="http://www.mamicode.com/images/nextthread.gif"width="48" height="12"border="0"></a></DIV> 
</TD> 
<TD><IMG 
height=16 src="http://www.mamicode.com/images/mail.gif"width=16></TD> 
<TD class="myfont"><A class="redtxt" 
href="http://www.mamicode.com/commend.php?id=<? echo"$data[id]&title=$data[title]";?>">推薦給朋友</A></TD> 
<TD> 發表時間: 
<? echo $data[time];?> 
閱讀次數: 
<? echo $data[hits];?> 
</TD> 
<TD>&nbsp; </TD> 
</TR> 
</TBODY> 
</TABLE> 
</TD></TR> 
<TR vAlign=top> 
<TD class="tenpt"> 
<? 
if($data[locked]<>0) 

echo "<img src=http://www.mamicode.com/images/lock.gif>對不起!本文已經被管理員鎖定!"; 

else 
if($data[html]==1) 
highlight_string($data[cont]); 
else 
echo nl2br($data[cont]); 
?> 
</TD> 
</TR> 
</TBODY></TABLE> 
<table bordercolor=#339933 cellspacing=0bordercolordark=#ffffff 
cellpadding=0 align=center bordercolorlight=#000000border=1 width=545> 
<tbody> 
<TR bgColor=#cccccc> 
<th> 
<DIV align=center>發表評論</DIV> 
</th> 
</TR> 
<tr> 
<td> 
<form name="form1"method="post" action="ping.php" onsubmit="returngo()"> 
您的姓名: 
<input type="text"name="name" class="border"> 
&nbsp;&nbsp;您的電子郵件: 
<input type="text"name="mail" size=20 class="border"> 
僅站長可見:<input type="checkbox"name="pub" value="http://www.mamicode.com/<? echo $data[title];?>"> 
<input type="hidden"name="p_id" value="http://www.mamicode.com/<? echo $id;?>"> 
<br> 
發表評論: 
<textarea name="cont"rows="8" cols="85"></textarea> 
<br> 
<br> 
<center> 
<input type="submit"name="Submit" value="http://www.mamicode.com/提交"class="border"> 
<input type="reset"name="Submit2" value="http://www.mamicode.com/重寫"class="border"> 
</center></form> 
</td> 
</tr> 
<TR bgColor=#cccccc> 
<th> 
<DIV align=center>相關評論</DIV> 
</th> 
</TR> 
<tr> 
<td> 
<? $query="select * from $ping_tab wherep_id=‘$id‘ order by time desc"; 
$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>&nbsp;&nbsp;".nl2br($ping[p_cont])."<br>時間:$ping[time] 來自:$ping[ip]<hrsize=1>n" ; 

else 
echo "暫時沒有本文章的相關評論!"; 
?> 
</td> 
</tr> 
<tr bgcolor=#cccccc> 
<td> 
<div align=center><a 
href="javascript:window.close()">關閉窗口</a></div> 
</td> 
</tr> 
</tbody> 
</table> 
<?require "./inc/footer.inc";?>。

PHP文章管理(2)