dz模板中常用的sql语句

语法语句

调用单个字段
$myUserName = DB::result(DB::query("SELECT username FROM ".DB::table('common_member')." WHERE uid = '1'"));

调用统计数据
$userCount = DB::result(DB::query("SELECT count(*) FROM ".DB::table('common_member')." WHERE uid = '1'"));


多数据表的调用

$perpage = 40;
$curpage = empty($_GET['page'])?1:intval($_GET['page']);
$start = ($curpage-1) * $perpage;
$acount = DB::result(DB::query("SELECT count(*) FROM ".DB::table('forum_forum'). "b LEFT JOIN ".DB::table('forum_forumfield')."bf ON bf.fid=b.fid WHERE b.type = 'sub'"));
$alist = array();
if($acount){
$query = DB::query("SELECT bf.*,b.* FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')."bf ON bf.fid = b.fid WHERE b.type = 'sub' ORDER BY bf.fid DESC LIMIT $start,$perpage");

while($value = DB::fetch($query)){
$alist[] = $value;
}
}

$multi = multi($account,$perpage,$curpage,"URL地址");


前台数据的显示

<!--{loop $alist $key $value}-->
<!--{eval $cover = DB::result(DB::query("SELECT attachment FROM ".DB::table ('forum_threadimage')." WHERE tid = '$value['tid']'"));}-->

$value[authorid]
<img src="$cover">

<!--{/loop}-->


时间戳

<!--{echo date("Y-m-d H:i:s",这里填写时间参数)}-->
2017-3-20 20:00:00
<!--{echo date("Y/m/d H:i:s",这里填写时间参数)}-->
2017/5/30 20:00:00
<!--{echo dgmdate(这里填写时间参数,'u','9999',getglobal('setting/dateformat')}-->
1分钟前/1天前

截取字符字数
<!--{echo cutstr(参数,40)}-->


表单提交
<form action="do.php?op=jiangchi&con=yes" method = "post" autocomplete="off">
<input type="hidden" value="{FORMHASH}" name = "formhash" />
最低奖金:<input name="qi" type="text" value="$qishi" />
最高奖金:<input name="end" type = "text" value = "$zhzh">
<button value="true" name="tijiao" type="submit">提交设置</button>
<input type = "hidden" name="tijiao" value="true" />
</form>


写入数据库

if(submitcheck('tijiao')){
$setarr = array(
'tid' => $_GET['topicid'],
'name' => $_POST['name'],
'position' => $_GET['position'],
'dateline' => $_G['timetamp'],
);
DB::insert('form_poststick',$setarr,1);
$query = DB::query("UPDATE ".DB::table('forum_thread'). " SET stickreply='1' WHERE tid = '$tid'");
$query = DB::query("DELETE FROM ".DB::table('forum_post')." WHERE pid = '$pid'");

showmessage('成功的提示信息',"forum.php?mod = viewthread&tid=$tid");

}

原文链接: dz模板中常用的sql语句 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-229.html )

发表评论

0则评论给“dz模板中常用的sql语句”