background image

4.

<?

php

5.

require_once 

"conn.php"

;

6.

$sql 

=

 

"select * from news"

;

7.

foreach

(

$dbh

->

query

(

$sql

)

 

as

 $row

){

8.

echo 

"<a 

href='news_{$row['id']}.html'>{$row['title']}</a>----<a 
href='add.php?id={$row['id']}'>修改文章</a><br>"

;

9.

}

10. ?>

4.添加修改文章页面:

1.

<meta

 

http-equiv

=

"content-type"

 

content

=

"text/html;charset=utf-8" 

/>

2.

<?

php

3.

//获取修改的内容

4.

if

(

$_GET

[

'id'

]){

5.

require_once 

"conn.php"

;

6.

$sql 

=

 

"select * from news where id={$_GET['id']}"

;

7.

$res 

=

 $dbh

->

query

(

$sql

)->

fetch

();

8.

}

9. ?>

10.

<form

 

action

=

"action.php"

 

method

=

"post"

>

11. 标题:<input type="text" name="title" value="

<?=

@$res

[

'title'

]?

>

"/>

<br/>

12. 内容:

<textarea

 

name

=

"content"

 

col

=

40

 

row

=

4

>

<?

=

@$res

[

'content'

]?>

</textarea><br/>

13. <input type="hidden" name="id" value="

<?=

$_GET

[

'id'

]?>

" />

14. <input type="submit" name="submit" value="

<?

php echo 

$_GET

[

'id'

]

 

?

 

'修改'

 

:

 

'添加'

?>

" />

15. </form>

5.用于生成静态文件的页面模板 template.html

1. <html>
2. <head>

3.

<title>

{title}

</title>

4.   

<meta

 

http-equiv

=

"content-type"

content

=

"text/html; charset=UTF-

8"

/>

5.

</head>

      

6. <body>