-----------主页代码开始------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>传媒</title>
</head>
<body>
<table align="center" width="100%">
<tr><td>新闻</td><td align="right"><a href="add.php?fl=1">添加新闻</a></td></tr>
</table>
<hr>
<table border="1" align="center" width="70%">
<tr><td align="center"><a href="index.php">新闻</a></td><td align="center"><a href="guonei.php">国内</a></td><td align="center"><a href="guoji.php">国际</a></td><td align="center"><a href="shehui.php">社会</a></td><td align="center"><a href="gongyi.php">公益</a></td>
</tr>
<?
//连接数据库mysql。 mysql_connect(ip,username,password)
$conn=mysql_connect("127.0.0.1","root","");
if(!$conn)
{
die("1连接数据库失败!");
}
$result=mysql_select_db("chuangyichuanmei_data",$conn);
if(!$result)
{
mysql_close($conn);
die("2指定数据库失败!");
}
$sql="set names utf8";
mysql_query($sql);//运行sql数据库查询语句,把结果保存在变量#rs中。
//查询数据
$sql="select * from t_news where flid=1";//查询数库中指定的表中分类是1的信息
$rs=mysql_query($sql);//运行sql数据库查询语句,把结果保存在变量#rs中。
if(!$rs)//如果运行不成功
{
//关闭数据库
mysql_close($conn);
//显示错误信息。程序到此为止,不往下执行了。
die("3数据查询失败!");
}
$recordcount=mysql_num_rows($rs);//得到sql运行返回的行数
if($recordcount>0)//如果有返回行数
{
//遍历每一行
while($row=mysql_fetch_assoc($rs))//得到一行
{
echo "<tr><td align='right'>";//右对齐
echo "<img src='images/".$row['picture']."'>";//显示图片的路
echo "</td>";
echo "<td colspan='4'><b><a href='show.php?id=".$row['n_id']."'>";//<b>为字体加粗。
echo $row['title'];//显示大标题
echo "</a></b>";
echo "</br>";//另起一行
echo "</br>";//写两个就加两行
echo $row['subtitle'];//显示小标题
echo "</br>";
echo $row['time'];//显示时间
echo "</td>";
echo "</tr>";