我写的代码如下:但是有问题 title页面 <?php session_start();include("conn/conn.php");?> <?php $query=mysql_query("select * from tb_xxgk order by id desc limit 20",$conn); while($row=mysql_fetch_array($query)) {
echo "<a href=content.php?id=".$row[id].">".$row[title]."</a><br>"; } ?> content页面 <?php include("conn/conn.php");?> <?phpif($_GET['id']){ $id=$row[id]; $query=mysql_query("select * from tb_xxgk where id='$id'",$conn); while($row=mysql_fetch_array($query)) {
echo "<br>$row[content]"; //打印文章内容 } } else{ //如果没有选择哪篇文章就打印第一篇 $query=mysql_query("select * from tb_xxgk order by id desc limit 1",$conn); while($row=mysql_fetch_array($query)){ echo "$row[content]"; } } ?> 执行时title页面有显示文章标题 但是点击标题content没有内容显示 是不是id没传过去所以没取得content字段中的内容?
if($_GET['id']){ $id=$row[id];//去掉这行 $query=mysql_query("select * from tb_xxgk where id='{$_GET["id"]}'",$conn); while($row=mysql_fetch_array($query)) {
<?php include("conn/conn.php");?> <?phpif($_GET['id']){ $id=$_GET['id']; $query=mysql_query("select * from tb_xxgk where id='$id'",$conn); $row=mysql_fetch_array($query); echo "$row[content]"; //打印文章内容 }else{ //如果没有选择哪篇文章就打印第一篇 $query=mysql_query("select * from tb_xxgk order by id asc limit 1",$conn); $row=mysql_fetch_array($query); echo "$row[content]";
title页面
<?php session_start();include("conn/conn.php");?>
<?php
$query=mysql_query("select * from tb_xxgk order by id desc limit 20",$conn);
while($row=mysql_fetch_array($query))
{
echo "<a href=content.php?id=".$row[id].">".$row[title]."</a><br>"; }
?>
content页面
<?php include("conn/conn.php");?>
<?phpif($_GET['id']){
$id=$row[id];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
while($row=mysql_fetch_array($query))
{
echo "<br>$row[content]"; //打印文章内容 }
}
else{ //如果没有选择哪篇文章就打印第一篇
$query=mysql_query("select * from tb_xxgk order by id desc limit 1",$conn);
while($row=mysql_fetch_array($query)){
echo "$row[content]";
}
}
?>
执行时title页面有显示文章标题 但是点击标题content没有内容显示 是不是id没传过去所以没取得content字段中的内容?
$id=$row[id];//去掉这行
$query=mysql_query("select * from tb_xxgk where id='{$_GET["id"]}'",$conn);
while($row=mysql_fetch_array($query))
{
<?php include("conn/conn.php");?>
<?phpif($_GET['id']){
$id=$_GET['id'];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
$row=mysql_fetch_array($query);
echo "$row[content]"; //打印文章内容
}else{ //如果没有选择哪篇文章就打印第一篇
$query=mysql_query("select * from tb_xxgk order by id asc limit 1",$conn);
$row=mysql_fetch_array($query);
echo "$row[content]";
}
?>