SoFunction
Updated on 2025-03-10

PHP+MYSQL article management system (II)

#####################################
<?session_start();
require"./inc/";
mscon();
require "./inc/";
?>
<script language="javascript">
function opwin(filename)
{                ("read_article.php?","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 style="position:absolute; left:7px; top:17px; width:43px; height:44px; z-index:2"><object class codebase="/pub/shockwave/cabs/flash/#version=5,0,0,0" width="80" height="60">
          <param name=movie value="images/">
          <param name=quality value=high>
          <param name="wmode" value="transparent">
          <embed src="images/" quality=high pluginspage="/shockwave/download/?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="80" height="60" wmode="transparent">
          </embed>
        </object></div>
      <div style="position:absolute; left:-5px; top:61px; width:49px; height:37px; z-index:1"><img src="images/" width="58" height="55"></div>
    </td>
    <td width="539"> <object class codebase="/pub/shockwave/cabs/flash/#version=5,0,0,0" width="468" height="60">
          <param name=movie value="images/">
          <param name=quality value=high>
          <param name="wmode" value="transparent">
          <embed src="images/" quality=high pluginspage="/shockwave/download/?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/" height="2">&nbsp;</td>
  </tr>
</table>
<table><FORM name=form1 action=  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=>all categories</option>
<? $typ=file("");
$num=count($typ);
for($i=2;$i<=$num;$i++)
{
  echo"<option value=$typ[$i]>$typ[$i]</option>";}
      ?>
  </select>
  <select name="whe">
<option value=>all content</option>
<option value=1>Article content</option>
<option value=2>Article title</option>
<option value=3>join time</option>
  </select>
  <input type="hidden" name="submit" value="1">
<input type="submit" name="submit" value="submit query">
  </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 where type='$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".$total_page."Page</td></tr>";
  if(empty($page))
    $page=0;
  if(empty($offset))
    $offset=0;
  $offset=$pagenum*$page;
  if(!empty($type))
     $query="select * from $table where type='$type' $sec order by id desc limit $offset,$pagenum";
  else
    $query="select * from $table $fir order by id 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 year m month d day))
           $topic[time]="<font color=#FF9900>$topic[time]</font>";
           echo" <tr><td>[$topic[type]]<a href=# onClick="opwin($topic[id])";>$topic[title]</a><font size=1>($topic[time])</font>";
        if($topic[comm]==1)
echo "<img src="./images/" alt="Quality Articles">";
        if($topic[locked]==1)
echo "<img src="./images/" alt="Article Locked">";
        echo "</td>
<td>Read: $topic[hits] times; Comments: $topic[p_num] times</td>
          </tr>";
     }
else
echo "Sorry, there are no articles in this column!!!";
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 "<a href="$php_self?page=$pre&type=$type">Previous page</a><br><br>";
else
echo "Previous page<br><br>"; ?></td>
    <td><?if($page<$total_page-1)
echo "   <a href="$php_self?page=$next&type=$type">Next page</a><br><br>";
else echo "   Next page<br><br>";?></td>
    <td>
<form> Jump to:
        <select name="page" onchange="='<? echo $php_self;?>?page='+[1].elements[0].value+'&type=<?echo $type;?>';" class="border">
          <?
  for($i=0;$i<$total_page;$i++)
    {
     $p=$i+1;
     echo "<option value=$i";
     if($page==$i) echo " selected" ;
echo ">Page ".$p."Page</option>n";
     }
?>
        </select> </form>
</td>
<td>
<form>Select column:
        <select name="type"  onchange="='<? echo $php_self;?>?type='+[2].elements[0].value<?if($comm) echo"+'&comm=1'";?>;" >
          <? $typ=file("");
$num=count($typ);
for($i=0;$i<$num;$i++)
{
  echo"<option value=$typ[$i] "; if(trim($typ[$i])==$type) {  echo "  selected"; } echo ">$typ[$i]</option>";}
      ?>
        </select>
    </form>
</td><td><form method="post" action=<? echo $PHP_SELF;?>?type=<?echo $type;?> target="_balnk"><input type="submit" name="comm" value="bout article" class=border></form></td>
</tr>
</table>
<?require "./inc/";?>
#####################read_article.php#########################
<?
require"./inc/";
if(!$id)
{
  echo"<script>();</script>";
   exit();
}
mscon();
$query="select * from $table where id='$id'";
$res=mysql_db_query("$database",$query);
if(!$res)
  {
    echo "this article has been deleted or no this article!!";
    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>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style type=text/css>
<!--
body,table,td,input,textarea {  font-family: "Stick"; font-size: 9pt}
select {  font-family: "Stick"; 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 ([0].elements[0].value == "" || [0].elements[0].value == "undefined" || [0].elements[0].value == "null")
  {
elem4 = prompt("Please enter your name: ","");
    theResult = false;
    [0].elements[0].value = elem4;
  }
  return theResult;
}
function mail()
{
  var theResult = true;
  var elem1 = null
  if (([0].elements[1].('@') == -1 || [0].elements[1].value == "" || [0].elements[1].('.') == -1))
  {
elem1 = prompt("Please enter your correct email address. Thank you!!","");
    theResult = false;
    [0].elements[1].value = elem1;
  }
  return theResult;
}
function go()
{
var theResult=true;
theResult = name()&&mail();
return theResult;
}
</script>
</HEAD>
<BODY text=#000000 bgColor=#ffffff>
<TABLE borderColor=#339933 cellSpacing=0 borderColorDark=#ffffff
cellPadding=0 align=center borderColorLight=#000000 border=1 width=545>
  <TBODY>
  <TR vAlign=center bgColor=#009900>
    <TD background=images/>
      <TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
        <TBODY>
        <TR>
          <TD width=17>&nbsp;</TD>
          <TD width=590>
            <TABLE width="36%" align=center border=0>
              <TBODY>
              <TR>
                <TD bgcolor="#009900">
                  <DIV align=center><FONT face="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><A href="javascript:()"><IMG height=17
            src="images/" width=17 align=absMiddle
            border=0 name=content_r03_c28></A></DIV>
          </TD></TR></TBODY></TABLE></TD></TR>
  <TR vAlign=center align=left bgColor=#cccccc>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 border=0 align="center" width="100%">
        <TBODY>
        <TR>
          <TD>
            <DIV align=left><A class=whitetxt
            href="read_article.php?id=<? echo  $pre;?>"><img src="images/" width="48" height="12" border="0"></A></DIV>
          </TD>
          <TD>
            <DIV align=left><a class=whitetxt
            href="read_article.php?id=<? echo $next;?>"><img src="images/" width="48" height="12" border="0"></a></DIV>
          </TD>
          <TD><IMG
            height=16 src="images/" width=16></TD>
          <TD class=myfont><A class=redtxt
href="?id=<? echo "$data[id]&title=$data[title]";?>">Recommended to friends</A></TD>
<TD> Published on:
            <? echo $data[time];?>
Number of reads:
            <? 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=images/> Sorry! This article has been locked by the administrator!";
}
else
  if($data[html]==1)
     highlight_string($data[cont]);
  else
     echo nl2br($data[cont]);
?>
      </TD>
  </TR>
  </TBODY></TABLE>
<table bordercolor=#339933 cellspacing=0 bordercolordark=#ffffff
cellpadding=0 align=center bordercolorlight=#000000 border=1 width=545>
  <tbody>
<TR bgColor=#cccccc>
    <th>
<DIV align=center>Leave a comment</DIV>
    </th>
  </TR>
  <tr>
    <td>
<form name="form1" method="post" action="" onsubmit="return go()">
Your name:
        <input type="text" name="name" class="border">
&nbsp;&nbsp;Your email:
        <input type="text" name="mail" size=20 class="border">
Only visible to the webmaster: <input type="checkbox" name="pub" value="<? echo $data[title];?>">
        <input type="hidden" name="p_id" value="<? echo $id;?>">
        <br>
Leave a comment:
        <textarea name="cont" rows="8" cols="85"></textarea>
        <br>
        <br>
        <center>
<input type="submit" name="Submit" value="submit" class="border">
<input type="reset" name="Submit2" value="rewrite" class="border">
        </center></form>
        </td>
  </tr>
  <TR bgColor=#cccccc>
    <th>
<DIV align=center>Related Comments</DIV>
    </th>
  </TR>
  <tr>
  <td>
<?  $query="select * from $ping_tab where p_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 "Commenter:$ping[name]   Email:$ping[mail]<br>&nbsp;&nbsp;".nl2br($ping[p_cont])."<br>Time:$ping[time]  From:$ping[ip]<hr size=1>n" ;
   }
   else
echo "There are no comments on this article for the time being!";
  ?>
  </td>
  </tr>
  <tr bgcolor=#cccccc>
    <td>
      <div align=center><a
href="javascript:()">Close the window</a></div>
    </td>
  </tr>
  </tbody>
</table>
<?require "./inc/";?>