php中调取最新列表及文章内容
一,调取最新列表
<html>
<head>
<meta charset="utf-8">
<title>lfwa.zrghs.com</title>
</head>
<body>
<ul>
<?php
/*
$articleList=array(array(articleid=>'1',title=>'文章1'),array(articleid=>'2',title=>'文章1'));
foreach($articleList as $article){
echo '<a href="articleContent.php?id='.$article['articleid'].'">'.$article['title'].'</a><br>';
}*/
$conn = new mysqli("localhost", "root", "root", "gszy.zrghs.com");
$list = $conn->query("select article_id,title,djs from article order by createtime desc limit 3");
while($row = $list->fetch_assoc()) {
echo "<li><a href='articleContent.php?id=".$row['article_id']."'>".$row['title']."</a><span style='color:red;'>".$row['djs']."</span></li>";
}
?>
</ul>
</body>
</html>
二内容显示
<?php
$articleid=$_GET['id'];
$conn = new mysqli("localhost", "root", "root", "czdg.zrghs.com");
$result = $conn->query("select * from article where article_id=".$articleid);
$sql="update article set djs=djs+1 where article_id=".$articleid;
if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
echo $row["content"];
}
} else {
echo "0 结果";
}
$conn->query($sql);
$conn->close();
?>