smarty 数据库查询有关问题
程序员文章站
2022-06-11 14:57:52
...
smarty 数据库查询问题
function class_id(){
if(!empty($_GET['class_id'])){
$sql="select * from goods_class as a,goods_detail as b where a.id=b.class_id and a.id='$_GET[class_id]'";
$query=mysql_query($sql);
while($row_class=mysql_fetch_array($query)){
$sm_class[]=array("name"=>$row_class['goods_name'],"id"=>$row_class['id'],"picture"=>$row_class['picture']);
}
}
return $sm_class;
//print_r($sm_class);
}
class_id();
$smarty->assign("sm_class",$sm_class);
if语句放到方法外可以再html中正常显示,上面这样写则不行,为什么?
------解决方案--------------------
$sm_class =class_id();
$smarty->assign("sm_class",$sm_class);
function class_id(){
if(!empty($_GET['class_id'])){
$sql="select * from goods_class as a,goods_detail as b where a.id=b.class_id and a.id='$_GET[class_id]'";
$query=mysql_query($sql);
while($row_class=mysql_fetch_array($query)){
$sm_class[]=array("name"=>$row_class['goods_name'],"id"=>$row_class['id'],"picture"=>$row_class['picture']);
}
}
return $sm_class;
//print_r($sm_class);
}
class_id();
$smarty->assign("sm_class",$sm_class);
if语句放到方法外可以再html中正常显示,上面这样写则不行,为什么?
------解决方案--------------------
$sm_class =class_id();
$smarty->assign("sm_class",$sm_class);
相关文章
相关视频
上一篇: mysql数据库如何设置一个字段不重复,一个字段自增?
下一篇: mysql安装过程中遇到的问题