Contoh pembangunan: paparkan 10 berita terkini


Tunjukkan 10 contoh pengaturcaraan berita terkini Penulisan kod program Format direktori storan:
Direktori storan program plug-in: /e/lanjutkan/berita baharu/
Direktori storan templat pemalam: /e/lanjutkan/berita baharu/templat/
Fail program yang diperlukan:
/e/extend/newnews/index.php Fail program utama
/e/extend/newnews/template/index.temp.php Fail templat program utama

Direktori Program Direktori Templat
Kandungan fail program utama(/e/extend/newnews/index.php):
<?php
require('../../class/connect.php'); //Perkenalkan fail konfigurasi pangkalan data dan fail fungsi awam
require('../../class/db_sql.php'); //Perkenalkan fail operasi pangkalan data
require('../../data/dbcache/class.php'); //Perkenalkan fail cache lajur
$link=db_connect(); //Sambung ke MYSQL
$empire=new mysqlquery(); //Isytiharkan kelas operasi pangkalan data
$editor=1; //Isytiharkan hierarki direktori

$sql=$empire->query("pilih * daripada {$dbtbpre}ecms_news order mengikut had masa berita 10"); //Soal 10 rekod terkini dalam jadual berita
require('template/index.temp.php'); //Import fail templat

db_close(); //Tutup pautan MYSQL
$empire=null; //Batalkan pembolehubah kelas operasi
?>


Kandungan fail templat program utama(/e/extend/newnews/template/index.temp.php):
Nota: Templat boleh dibuat secara visual dengan Dreamweaver. Bahagian biru kod tidak membenarkan akses terus ke fail templat.
<?php
if(!defined('InEmpireCMS'))
{
keluar();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text /html; charset=gb2312">
<title>Paparkan 10 contoh berita terkini</title>
</head>
<body>
<br>
<br>
<br>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height=" 25 "><strong>Tunjukkan 10 berita terkini: </strong></td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF" > ;                
<jadual lebar = "100%" sempadan = "0" jarak sel = "0" cellpadding="0">
                                                                                                                                                                                                                                                                                                                                                                                //Gelung untuk mendapatkan rekod pertanyaan
                                                                                                $titleurl=sys_ReturnBqTitleLink($r); //Pautan tajuk
              ?>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                height="25">·<a href="<?=$titleurl?>" target="_blank">                     <?=esub(garis sebatan($r[tajuk]),32)?>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  "><div align="center">[<?=date('Y-m-d',$r[newstime])?>]</div></td>
                                                                                                                                                                                                                                                                                                                                         }
              ?>
                                                                                                                                                                                                                                                           </td>
</tr>
</table>
</body>
</html>



Akses program utama fail pemalam Hello World: /e/extend/newnews/index.php