Discuz如何添加数据DB::insert和更新数据DB::update查询DB::qu

discuz教程:如何添加数据DB::insert和更新数据DB::update 查询DB::qu!

添加数据DB::insert

$uid=empty($_POST['uid']) ? "" : $_POST['uid'];
$username=empty($_POST['username']) ? "" : $_POST['username'];
$display_type=empty($_POST['display_type']) ? "" : $_POST['display_type'];
$filename=empty($_POST['filename']) ? "" : $_POST['filename']; 
$details=empty($_POST['details']) ? "" : $_POST['details'];
$videoname=empty($_POST['videoname']) ? "" : $_POST['videoname'];
//$sql="insert into pre_home_video(uid,display_type,filename,default) values('$uid','$display_type','$filename','$default')";
//$query = DB::query($sql);
if(!empty($_POST['uid']) && !empty($_POST['display_type']) && !empty($_POST['display_type'] ))
{
$count = DB::result(DB::query("select uid from pre_common_member where uid= $uid"), 0);
if($count)
{
$arr=array();
$arr['uid'] = $uid;
$arr['username'] = $username;
$arr['display_type'] = $display_type;
$arr['filename'] = $filename; 
$arr['details'] = $details;
$arr['videoname'] = $videoname;
if(!file_exists("data/video/{$uid}")){
mkdir("data/video/{$uid}", 0700);
}
if(!file_exists("data/video/{$uid}/cover")){
mkdir("data/video/{$uid}/cover", 0700);
}
$count1=DB::insert('home_video',$arr);
if($count1)
{
echo("<script type='text/javascript'>alert('添加成功');window.location = \"admin.php?action=video\";</script>");
 
}
}
else
{
echo("<script type='text/javascript'>alert('添加失败,该用户不存在');</script>");
}

更新

$id = $_GET['id'] ? $_GET['id'] : 0;
$query = DB::query("select * from ".DB::table('home_hall')." where id=$id");
if($query){
$data = DB::fetch($query);
if($type == 'gold'){
if($op == 'add'){
$data['isgold'] = 1;
}elseif($op = 'cancle'){
$data['isgold'] = 0;
}
DB::update('home_hall', array('isgold'=>$data['isgold']),array('id'=> $id));
}elseif($type == 'index'){
if($op == 'add'){
$data['isindex'] = 1;
}elseif($op = 'cancle'){
$data['isindex'] = 0;
}
DB::update('home_hall', array('isindex'=>$data['isindex']),array('id'=> $id));
}
}else{
echo '没有此展厅';
}

查询,返回结果集

$perpage = 25;
$start = ($page-1)*$perpage;
$mpurl = ADMINSCRIPT.'?action=goldhall';
$count = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('home_hall')), 0);
if($count){
$query = DB::query("SELECT * FROM ".DB::table('home_hall')." limit $start, $perpage");
while ($value = DB::fetch($query)) {
$list[] = $value;
}
$multipage = multi($count, $perpage, $page, $mpurl);
}
 
echo '<table width="100%" border=1>';
echo '<tr><td>用户id</td><td>展厅名</td><td>展厅级别</td><td>联系电话</td><td>操作</td><td>操作</td></tr>';
foreach ($list as $k => $v){
echo "<tr>";
echo "<td>{$v['uid']}</td>";
echo "<td>{$v['hallname']}</td>";
echo $v['isgold'] ? "<td>金牌</td>" : "<td>普通</td>";
echo "<td>{$v['telephone']}</td>";
if($v['isgold'] == 1){
echo "<td><a href='admin.php?action=goldhall&id={$v['id']}&type=gold&op=cancle'>取消金牌展厅</a></td>";
}else{
echo "<td><a href='admin.php?action=goldhall&id={$v['id']}&type=gold&op=add'>升级</a></td>";
}
if($v['isindex'] == 1){
echo "<td><a href='admin.php?action=goldhall&id={$v['id']}&type=index&op=cancle'>取消首页推荐</a></td>";
}else{
echo "<td><a href='admin.php?action=goldhall&id={$v['id']}&type=index&op=add'>首页推荐</a></td>";
}
echo "</tr>";
}
echo '</table>';
if($multipage){
echo $multipage;
} 
//删除
if($_GET['op'] == 'delete'){
if($gid){ //还要删除文件
DB::delete('saige_geku', array('id' => $gid));
DB::delete('saige_gekufield', array('gid' => $gid));
DB::delete('saige_gkcomment', array('gid' => $gid));
}
 
}
温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

Discuz如何把导航修改成100%显示?

2020-11-11 0:00:00

编程技巧

织梦栏目伪静态后仍然自动生成空文件夹的解决方法

2020-11-13 0:00:00

0 条回复 A文章作者 M管理员
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索