list.php文件里使用一下代码:
<?php
include_once ('global.php');
//if(empty($_GET[cid])) exit();
$sql = "SELECT * FROM `p_newsclass` where f_id=0 order by id DESC";
$query = $db->query($sql);
while ($row_class = $db->fetch_array($query)) {
$sm_class[] = array (
"name" => $row_class[name],
"id" => $row_class[id]);
}
$smarty->assign("sm_class", $sm_class); //导航引入
//*******************************
$sql = "SELECT * FROM p_config";
$query = $db->query($sql);
while ($row_config = $db->fetch_array($query)) {
$sm_config[] = $row_config[values];
}
$smarty->assign("sm_config", $sm_config); //配置引入
//***********************************
$query = $db->findall("p_newsclass");
while ($row = $db->fetch_array($query)) {
$news_class_arr[$row[id]] = $row[name];
}
$query = $db->findall("p_newsclass where f_id='$_GET[cid]'");
while ($row = $db->fetch_array($query)) {
$news_class_in.= $row[id].",";
$news_class_list_arr[] =array("name"=>$row[name],"id"=>$row[id],);
}
$news_class_in=$news_class_in."$_GET[cid]";
$result = mysql_query("select id from p_newsbase where cid in ($news_class_in)");//
$total = mysql_num_rows($result);
pageft($total, 2);
if ($firstcount < 0)
$firstcount = 0;
$query = $db->findall("p_newsbase where cid in ($news_class_in) limit $firstcount, $displaypg"); //where cid in ($news_class_in)
while ($row = $db->fetch_array($query)) {
$sm_list[] = array (
"cid" => $row[cid],
"cidname" => $news_class_arr[$row[cid]],
"title" => $row[title],
"id" => $row[id],
"date_time" => date("m/d",$row[date_time]));
}
$smarty->assign("sm_list", $sm_list); //新闻列表
$smarty->assign("pagenav", $pagenav); //新闻分页
$smarty->assign("news_class_list_arr", $news_class_list_arr); //新闻子类
$smarty->assign("t_dir",$smarty_template_dir);//更换模板图片路径
$smarty->display("list.htm");
?>
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\php\PHPnew\list.php on line 41
错误信息提示:
错误号:12142
错误原因:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') limit 0, 2' at line 1
错误SQL语句:
SELECT * FROM p_newsbase where cid in (1,7,14,11,) limit 0, 2
——错误记录被保存!
因为$news_class_in.= $row[id].",";导致SELECT * FROM p_newsbase where cid in (1,7,14,11,) limit 0, 2里面多了个逗号,解决方法:
替换掉里面的内容:
$query = $db->findall("p_newsclass where f_id='$_GET[cid]'");
while ($row = $db->fetch_array($query)) {
$news_class_in.=$row[id].",";
$news_class_list_arr=array("name" => $row[name],"id"=>$row[id]);
}
if($_GET[cid]){
echo $news_class_in=$news_class_in."$_GET[cid]";
}else{
$query = $db->findall("p_newsclass");
while ($row = $db->fetch_array($query)) {
$news_class_in.=$row[id].",";
}
$news_class_in=substr($news_class_in,0,-1);
}
$result = mysql_query("select `id` from `p_newsbase` where `cid` in ($news_class_in)");