如何自动把最新发布的文章显示在最前面 附代码 跪求下面ID被固定成$id= 206
我想id显为最新的id号,目前最新的是211,可每次打开页面都显示id205的内容,想改成每次打开内面显示的内容是211(也就是最新的id)
代码如下:<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$id = g('id');
!is_numeric($id) && $id = 206;
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
我想id显为最新的id号,目前最新的是211,可每次打开页面都显示id205的内容,想改成每次打开内面显示的内容是211(也就是最新的id)
代码如下:<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$id = g('id');
!is_numeric($id) && $id = 206;
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
本人新学,是改别人之前做好的,每次打开页面,里面显示的内容都是id206内容,现在最新发布的内容id是211(最新的),可不可以在上面的代码中改成自动显示最新的id,??能说详细点不??
http://www.g3yx.net/newsshow.php
echo $id; //贴出结果
!is_numeric($id) && $id = 206; //这句是不是没写完整?
<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$id = g('id');
!is_numeric($id) && $id = 206;
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
$sql .= 'ORDER BY a.id DESC';
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
http://www.g3yx.net/newsshow.php你帮我看下,万分感谢哦:以下是全部的代码:<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$id = g('id');
!is_numeric($id) && $id = 206;
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="images/css.css" type="text/css" rel="stylesheet" />
<title><?=$title ?> - G3映像</title>
<style type="text/css">
<!--
.STYLE1 {color: #CCCCCC}
.STYLE2 {
font-family: "宋体";
font-weight: bold;
font-size: 14px;
}
.STYLE3 {font-size: 14px}
.STYLE4 {font-size: 10px}
.STYLE6 {font-family: "宋体"; font-weight: bold; font-size: 14px; color: #444444; }
.STYLE7 {
color: #444444;
font-weight: bold;
}
.STYLE8 {color: #FF0000}
.STYLE9 {
color: #FFFFFF;
font-size: 14px;
font-weight: bold;
}
.STYLE10 {color: #FFFFFF}
-->
</style>
</head><body>
<table width="980" border="0" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF">
<tr>
<td style="border:1px solid #FFCC00;">
<table width="100%" border="0" cellpadding="0" cellspacing="10" >
<tr>
<td class="weizhi">您的位置:<a href="index.php">首页</a> > <a href="#">快乐空间</a> > <a href="#"><?=$fname ?></a> ><?=$title ?></td>
</tr>
<tr>
<td align="center"><h1><?=$title ?></h1><span>发布时间:<?=$junjun_time ?> 点击次数:<?=$visit+1 ?></span></td>
</tr>
<tr>
<td align="center" class="newcn"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="STYLE3" style="width:709px;overflow:hidden"><br>
<div style="width:709px;overflow:hidden"><?=$cn ?></div></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
<td width="240" valign="top"><table width="240" height="310" border="0" cellpadding="0" cellspacing="0" background="images/photopaihang.jpg">
<tr>
<td align="center" valign="top"><table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="35" class="tab2"><?=$fname ?></td>
</tr>
<tr>
<td ></td>
</tr>
<?php
unset($sql);
$sql = cha('*','news',"funid=$funid",'createtime desc','0,10');
while ($rows1 = fetch($sql)){
?>
<tr>
<td height="20" valign="bottom" class="rightmenu"><img src="images/dot.gif" width="5" height="7" border="0"/> <a href="?id=<?=$rows1["id"]?>" title="g3摄影工作室"><?=$rows1["title"]?></a></td>
</tr>
<?php
}
?>
<tr>
<td height="1" class="newcn"></td>
</tr>
</table> </td>
</tr>
</table><br/>
<img src="images/youhuiquans.jpg" width="238" height="132"></td>
</tr>
</table>
<?php
include_once("newfood.php");
?>
</body>
</html>
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
echo $sql;exit;
$rows = fetch($sql);看看输出的是什么,打出来看看
输出是:Resource id #6
那id就不要用了。
这样试试。
看不到你那些函数是怎么写的。基本靠猜。<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id','','','');
$sql .= ' ORDER BY a.id DESC LIMIT 1 ';
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
echo sql 是输出是:Resource id #6
出错了:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\include\function.php on line 18
那我再猜一个吧。<?php
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',' AND 1 ORDER BY a.id DESC LIMIT 1 ','','');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>
或者
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','order by a.id desc');
试一试
echo $id; //贴出结果g()方法也不知道是怎么写的。 你想怎么解决呢?
如果:
$id = g('id');
!is_numeric($id) && $id = 206;
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"a.id=$id",'','');
echo $id;
作输出206
SELECT *
FROM `news`
ORDER BY `id` DESC
LIMIT 0 , 60
找function cha 函数贴代码出来。
还有你不是要显示最新的一条出来吗、所以就不要纠结id了。ORDER BY id LIMIT 1 就是最新的一条。
$id = g('id'); 这行下面加上:
echo $id; 看是什么结果。还有把你的g()方法也贴出来。
<?phpfunction cha($ziduan,$biao,$tiaojian,$paixu,$page){
$tiaojian != '' && $tiaojian = "where ".$tiaojian;
$paixu != '' && $paixu = "order by ".$paixu;
$page != '' && $page = "limit ".$page;
$jieguo = mysql_query("select $ziduan from $biao $tiaojian $paixu $page");
return $jieguo;
}
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"",'a.id','1');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>改成这样。楼主你可以结贴拉
include_once("head.php");
include_once("include/conn.php");
include_once("include/function.php");
$sql = cha('a.*,b.fname','news a inner join tfunction b on a.funid=b.id',"",'a.id DESC','1');
$rows = fetch($sql);
$smallpic = $rows['smallpic'];
$funid = $rows['funid'];
$fname = $rows['fname'];
$title = $rows['title'];
$junjun_time = $rows['createtime'];
$visit = $rows['visit'];
$cn = $rows['cn'];
?>