phpcms使用sql语句
文章描述:
phpcms在模板里面使用sql语句调用文章
1、单表
{pc:get sql="SELECT * FROM v9_news WHERE catid='1' and id='1'" cache="3600" return="data"}
{loop $data $val}
{$val[title]}
{/loop}
{/pc}
2、连表
<?php $i=1;?>
{pc:get sql="select `b`.`content` from `v9_news` as `a` left join `v9_news_data` as `b` on `a`.`id`=`b`.`id` where `a`.`catid`='$i' order by `a`.`id` desc" num="10"}
{loop $data $r}
{$r[content]}
{/loop}
{/pc}
3、foreach
{pc:get sql="SELECT * FROM v9_news WHERE catid='1' " cache="3600" return="data"}
{loop $data $val}
{$val[title]}
<?php $id = $val['id'];
$sql = "SELECT `content` FROM `v9_news_data` WHERE `id`='$id' LIMIT 0 , 1";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
echo $row[content];
}
?>
{/loop}
{/pc}
发布时间:2021/06/29
发表评论