SoFunction
Updated on 2025-04-09

News classification entry and display system

This system can enter titles, content, pictures, and related software. When displaying, it will determine whether the content is displayed based on whether there are pictures and related software. The page that opens is displayed is the latest article, and clicking on the directory will display the previous article.
Create channelsmages and channelsoft directories and set permissions to 777.
*********************************
news table structure
*********************************
# Host: localhost Database : yourdb
# --------------------------------------------------------

#
# Table structure for table 'yourtable'
#

CREATE TABLE news(
   id int(11) DEFAULT '0' NOT NULL auto_increment,
   kind varchar(16),
   title varchar(60),
   content text,
   pic varchar(30),
   timer datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
   soft varchar(30),
   PRIMARY KEY (id),
   KEY timer (timer)
);

*********************************
News entry file:
*********************************
<html>
<head>
<title>News entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<form name="form1" enctype="multipart/form-data" action="" method="post" >
  <table width="81%" border="0" cellspacing="2" cellpadding="0" align="center">
    <tr>  
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFF">Title:</font></td>
      <td bgcolor="#E7E7E7">  
        <input type="text" name="title" size="60">
      </td>
    </tr>
    <tr>  
<td align="right" bgcolor="#CC0000"><font color="#FFFFF">Category:</font></td>
      <td bgcolor="#E7E7E7">  
<input type="radio" name="kind" value="type 1">
Type 1
<input type="radio" name="kind" value="type 2">
Type 2
<input type="radio" name="kind" value="type 3">
Type 3
<input type="radio" name="kind" value="type 4">
Type 4</td>
    </tr>
    <tr>  
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFF">Content:</font></td>
      <td bgcolor="#E7E7E7">  
        <textarea name="content" cols="60" rows="10"></textarea>
      </td>
    </tr>
    <tr>  
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFF">Picture:</font></td>
      <td bgcolor="#E7E7E7">  
        <input type="file" name="pic" size="60">
      </td>
    </tr>
    <tr>  
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFF">Software:</font></td>
      <td bgcolor="#E7E7E7">  
        <input type="file" name="soft" size="60">
      </td>
    </tr>
    <tr>  
      <td width="11%" align="right" bgcolor="#CC0000">&nbsp;</td>
      <td bgcolor="#E7E7E7">  
        <div align="center">  
<input type="submit" name="Submit" value="Submit">
        </div>
      </td>
    </tr>
  </table>
</form>
</body>  
</html>  
*********************************
end of
*********************************

*********************************

*********************************
<?
$day=date("md");
If($pic != "none"){
$picname=$day.$pic_name;
copy($pic,"channelimages/$picname");
unlink($pic);
}
If($soft!= "none"){
copy($soft,"channelsoft/$soft_name");
unlink($soft);
}
$dbh =  mysql_connect('localhost','uesrname','passward');
mysql_select_db('yourtable');  
$dat=date("Y-m-d h:i:s");
$query="insert into news(title,kind,content,pic,timer,soft) values('$title','$kind','$content','$picname',now(),'$soft_name')";
$res = mysql_query($query,$dbh);  

$err = mysql_error();
if($err){echo $err;exit();}
echo "<p></p><p align=center>";
echo "<body><h2>Entered successfully</h2></body></p>";
?>
*********************************
end of
*********************************

*********************************
News display files:
*********************************
<html>
<head>
<title>Display Type 1</title>
<meta http-equiv="directory type" content="text/html; character set=gb2312">
</head>
<body bgcolor="#FFFFFF">
<?
$db=mysql_connect("localhost","username","passward");
mysql_select_db("yourtable",$db);
$result=mysql_query("select id,title from news where kind='type 1' order by timer desc");
for($a=0;$a<10;$a++)
{if(!($ahrow=mysql_fetch_row($result)))break;
$id=mysql_result($result,$a,"id");
$title=mysql_result($result,$a,"title");
echo "<a href=?>".$title."</a><br>";
}
if (!isset($id)) $id=mysql_result($result1,0,"id");
$result=mysql_query("select * from news where id=$id order by timer desc");
$rows=mysql_fetch_row($result);
echo "<br><center><font color=ff0000>";
print $rows[2];
echo "</font><br>$rows[5]</center>";
if (strlen($rows[4])>0) echo "<p><img src=channelimages/$rows[4] align=right>";
echo str_replace("\r","<br>",str_replace(" ","&nbsp;",$rows[3]));
if (strlen($rows[6])>0) echo "</p><p align=right><a href=channelsoft/$rows[6]>>>Click to download</a></p>";
?>
</body>
</html>
*********************************
end of
*********************************


[The copyright of this article is jointly owned by the author and Aoso.com. If you need to reprint it, please indicate the author and source]