首页 > 学习 > 网络编程 > php > phpblog笔记(3)显示博客文章

phpblog笔记(3)显示博客文章

分享&收藏
时间:2010-09-25 17:23:52   
  [导读] 1,添加数据库链接代码
在header.php添加:
$db = mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbdatabase,$db);2.创建查询 所需sql语句:
select entries.*, categories.cat from entr...
  [正文]

 

1,添加数据库链接代码
 在header.php添加:
 $db = mysql_connect($dbhost,$dbuser,$dbpassword);
 mysql_select_db($dbdatabase,$db);

2.创建查询

 所需sql语句:
  select entries.*, categories.cat from entries ,categories 
   where entries.cat_id=categories.id
   order by dateposted desc
   limit 1;

 添加代码到index.php
  require("header.php");

 $sql = "select entries.*, categories.cat from entries ,categories 
   where entries.cat_id=categories.id
   order by dateposted desc
   limit 1;";
 
 $result = mysql_query($sql);
 $row= mysql_fetch_assoc($result);

 echo "<h2><a href='viewentry.php?id=" .$row['id']. "'>" .$row['subject'].
  "</a></h2><br />";

 echo "<i>in <a href='viewcat.php?id= " .$row['cat_id']. "'>"  . $row['cat'] . "</a> - Posted on " . date("D js F Y g.iA",strtotime($row['daeposted'])) .
 "</i>";

 echo "<p>";
 echo nl2br($row['body']);
 echo "</p>";

** nl2br()函数,将空行转换为正规的html<br />标签.最后一行关闭标签.

返回本文所属专题php入门笔记php入门笔记专题

 

相关图文

    热门图文
    最新文章