m_Orchestrate learning system---三十二、数据库字段判断为空时容易出现问题,如何从根本上解决这个问题

一、总结

一句话总结:字段禁止为空,设置默认值0即可

禁止 空 默认值

1、thinkphp查询数据库时判断字段是否为null?

字段 null
字段 值 = null

[NOT] NULL :

查询字段是否(不)是Null,例如:

where('name', null);
where('title','null');
where('name','not null');

如果你需要查询一个字段的值为字符串null或者not null,应该使用:

where('title','=', 'null');
where('name','=', 'not null');

2、数据库字段判断为空时容易出现问题,如何从根本上解决这个问题?

禁止 空 默认值

字段禁止为空,设置默认值0即可

3、学生分组分为所有(全部),未分组,对应分组,具体如何实现?

所有 -1
未分组 0

全部设置为-1,未分组的设置为0,php去数据的时候为-1则不加对应的条件判断

因为在之前的操作中很喜欢将所有设置为0而不是这里的-1

html

 <select class="form-control btn-sm" name="u_ugid" id="u_ugid" onchange="javascript:location.href=this.value;">
<option value="{:url('institution.group/grouping',array('gid'=>-1))}" selected >All</option>
<option value="{:url('institution.group/grouping',array('gid'=>0))}" {if condition="$gid eq 0"}selected{/if} >No Grouped</option>
{volist name="groups" id="vo"}
<option value="{:url('institution.group/grouping',array('gid'=>$vo.gid))}" {if condition="$vo.gid eq $gid"}selected{/if} >{$vo.gname}</option>
{/volist}
</select>

php

     public function grouping(){
//將小組信息傳遞到頁面
$groups=db('group')->select();
$this->assign('groups',$groups); $gid=input('gid');
if(is_null($gid)) $gid=-1;
$this->assign('gid',$gid);
//dump($gid);die; //將學生用戶傳遞到頁面
$map=null;
$map['u_status']=0;
if($gid!=-1) $map['u_ugid']=$gid;
$users=db('user')->alias('u')->
join('group g','u.u_ugid=g.gid','LEFT')->where($map)->paginate(10);
//dump($users);die;
$this->assign('users',$users);
return view();
}

4、bootstrap栅格系统?

col-md

 <div class="row">
<div class="col-md-2">
<h3 class="box-title text-info" style="padding-top:8px;margin-bottom: 10px; ">資源列表</h3>
</div>
<div class="col-md-10">
<select class="btn-sm" onchange="javascript:location.href=this.value;" style="margin-bottom: 10px;">
<option {if condition="$a_jieduan_id lt 1"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>0))}">All</option>
<option {if condition="$a_jieduan_id eq 1"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>1))}">WeEngage</option>
<option {if condition="$a_jieduan_id eq 2"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>2))}">WeExplore</option>
<option {if condition="$a_jieduan_id eq 3"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>3))}">WeAnalyze</option>
<option {if condition="$a_jieduan_id eq 4"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>4))}">WeExplain</option>
<option {if condition="$a_jieduan_id eq 5"} selected="" {/if} value="{:url('article/index',array('a_jieduan_id'=>5))}">WeReflect</option>
</select>
<select class="btn-sm" onchange="javascript:location.href=this.value;" style="margin-bottom: 10px;">
<option value="">學校學下學校</option>
<option value="">學校</option>
<option value="">學校</option>
</select>
<select class="btn-sm" onchange="javascript:location.href=this.value;" style="margin-bottom: 10px;">
<option value="">班級一</option>
<option value="">班級</option>
<option value="">班級</option>
</select>
<select class=" btn-sm" onchange="javascript:location.href=this.value;" style="margin-bottom: 10px;">
<option value="">小組一</option>
<option value="">小組</option>
<option value="">小組</option>
</select>
<select class="btn-sm" onchange="javascript:location.href=this.value;" style="margin-right: 10px;margin-bottom: 10px;">
<option value="">老師</option>
<option value="">學生</option>
</select>
<a href="" class="btn btn-sm btn-danger">確定</a>
</div>
</div>

5、html布局的时候如何让前后两个产生间距,但是分成两行的时候还是从头起(就是不能是margin-left)?

margin-right

不能是margin-left,如果是margin-left,另起一行的时候就会和左边有间距

所以可以是前一个的margin-right

6、在老師-管理員端文章頁面文章页面显示时,实现管理员登录看到全部文章,老师登录只能看到本班的文章,本班的文章包括老师文章和学生文章,就是需要实现找出班级号是**或者小组号是**的文章?

评论 回复 where function use

多应该多看手册下面的评论和回复的,里面有

SELECT * FROM test WHERE cert_type = 2 AND ( cert_terminology LIKE 0 OR cert_licencing LIKE 0 OR member_id IN (1,2,3) )

请问这个查询如何写出来

Db::name('test')
->where('cert_type',2)
->where(function ($query){
$query->where('cert_terminology','like',0)
->whereOr('cert_licencing','like',0)
->whereOr('member_id','in',[1,2,3]);
})
->select();

当有变量参数的时候

Db::name('test')
->where(function ($query) use ($user_id1, $user_id2){
$query->where([
'user_id1'=> $user_id1,
'user_id2'=> $user_id2
]);
})
->whereOr(function ($query) use ($user_id1, $user_id2){
$query->where([
'user_id1'=>$user_id2,
'user_id2'=>$user_id1
]);
})
->select();

最后代码

$articles=db('article')->alias('a')->
join('user u','u.u_id=a.a_authorid')->
join('group g','u.u_ugid=g.gid','LEFT')->
join('school_class sc','u.u_class=sc.sc_id','LEFT')->where($map1)->
where(function ($query) use($user,$teacher_gids){
$query->where('sc_id','=',$user['u_class'])->whereOr('gid','in',$teacher_gids);
})->
paginate(15);

可以朝这个方向,thinkphp的in转sql的in还没解决

$teacher_gids=\app\admin2\model\resource1\Article::getGroups_id($user['u_class']);
$teacher_gids='('.implode(',',$teacher_gids).')';
$articles=db('article')->alias('a')->
join('user u','u.u_id=a.a_authorid')->
join('group g','u.u_ugid=g.gid','LEFT')->
join('school_class sc','u.u_class=sc.sc_id','LEFT')->where($map1)->
where('sc_id = :sc_id OR gid = :teacher_gids',['sc_id'=>$user['u_class'],'teacher_gids'=>17])->
paginate(15);
//$map1['gid']=['in',$teacher_gid];

配合

where('sc_id = :sc_id OR gid in :teacher_gids',['sc_id'=>$user['u_class'],'teacher_gids'=>$teacher_gids])

生成:

SELECT COUNT(*) AS tp_count FROM `mo_article` `a` INNER JOIN `mo_user` `u` ON `u`.`u_id`=`a`.`a_authorid` LEFT JOIN `mo_group` `g` ON `u`.`u_ugid`=`g`.`gid` LEFT JOIN `mo_school_class` `sc` ON `u`.`u_class`=`sc`.`sc_id` WHERE `u_status` = '0' AND ( sc_id = '13' OR gid in '(16,17,18)' ) LIMIT 1

正确的sqlin语句如下: 用法:select * from where field in (value1,value2,value3,…)

区别就是括号上面没有引号

7、thinkphp中的whereor是什么意思?

整体 or

是整体的or,不是局部的or,就是判断条件上

join('school_class sc','u.u_class=sc.sc_id','LEFT')->where($map1)->
where('sc_id','=',$user['u_class'])->whereor('gid','in',$teacher_gids)->

不管其它两个where是什么内容,whereor都会执行

8、ueditor动态改变宽度?

百度 文档 引擎
ueditor 网页 产物 调

百度上啥都有,傻傻找API和文档找不到的时候一定记得去搜索引擎上面找一找

ueditor是网页的产物,没有API我们照样可以像调网络元素那样调,一样的

 <!-- ueditor -->
<script type="text/javascript">
var $=jQuery;
var ueditor_width=$('.myEditor').width();
//$('.myEditor').css({'border':'5px ridge #ff00ff'});
//alert(width);
UE.getEditor('{$ueditorID}',{
initialFrameWidth:ueditor_width,
initialFrameHeight:200,
}); //ueditor自動調節高度函數
function ueditor_setWidth(){
var ueditor_width=$('.myEditor').width();
$('.myEditor #edui1').css('width',ueditor_width);
} //頁面尺寸改變編輯器的大小自動改變
$(window).resize(function(){
ueditor_setWidth();
});
</script>

9、响应式表格?

table-responsive

不是在table上面加,是在table外的div上面加

10、tp5出现Illegal string offset 'eq_e_id'?

百度 数组名 相同

问题解决不了,百度

是由于数组名取相同

在volist-vo循环里面又多了一个volist-vo循环,vo被重新复制,所以影响了后面的vo,所以会出现Illegal string offset 'eq_e_id'

 {if condition="strlen($vo['eq_stem_picture'])>0"}
<div class="form-group">
<label for="eq_stem_picture">
題目題幹圖片(可選多張)
<small class="text-danger">最多20張,大小總和不超過500M</small>
</label> <div class="fry_file">
<button type="button" class="btn btn-danger btn-sm" disabled>
<i class="fa fa-upload"></i> Select images to upload</button>
<input class="fry_file_input" id="eq_stem_picture" type="file" accept="image/*" name="eq_stem_picture[]" multiple disabled>
</div>
<div id="file-list">
<?php
$eq_stem_pictures = explode(",,",$vo['eq_stem_picture']);
?>
{volist name="eq_stem_pictures" id="vo4"}
<?php if(strlen($vo)<=0) continue;?>
<img src="{$vo4}" alt="" style="max-width: 45%;" class="img-thumbnail">
{/volist}
</div>
</div>
{/if} <div class="form-group">
<label for="eq_e_id">題目所屬的試卷</label>
<div>
<select data-am-selected="{btnSize: 'sm'}" class="fry_select" name="eq_e_id" disabled>
<option {if condition="$vo.eq_e_id eq 0"} selected {/if} value="0">不屬於試卷</option>
{volist name="exams" id="vo3"}
<option {if condition="$vo['eq_e_id'] eq $vo3.e_id"} selected {/if} value="{$vo3.e_id}">{$vo3.e_title}-{$vo3.e_subtitle}</option>
{/volist}
</select>
</div>
</div>
id="vo4"里面的vo4本来是vo所以会报错

二、内容在总结中

 

m_Orchestrate learning system---三十二、数据库字段判断为空时容易出现问题,如何从根本上解决这个问题的更多相关文章

  1. 微信小程序把玩(三十二)Image API

    原文:微信小程序把玩(三十二)Image API 选择图片时可设置图片是否是原图,图片来源.这用的也挺常见的,比如个人中心中设置头像,可以与wx.upLoadFile()API使用 主要方法: wx. ...

  2. m_Orchestrate learning system---十三、thinkphp的验证器支持多语言么

    m_Orchestrate learning system---十三.thinkphp的验证器支持多语言么 一.总结 一句话总结:支持,不仅验证器支持,其它的插件应该都支持 不仅thinkphp支持多 ...

  3. FreeSql (三十二)Aop

    FreeSql AOP 已有的功能介绍,未来为会根据用户需求不断增强. 审计 CRUD 马云说过,996是修福报.对于多数程序员来说,加班是好事...起码不是闲人,不会下岗. 当如果因为某个 sql ...

  4. JAVA之旅(三十二)——JAVA网络请求,IP地址,TCP/UDP通讯协议概述,Socket,UDP传输,多线程UDP聊天应用

    JAVA之旅(三十二)--JAVA网络请求,IP地址,TCP/UDP通讯协议概述,Socket,UDP传输,多线程UDP聊天应用 GUI写到一半电脑系统挂了,也就算了,最多GUI还有一个提示框和实例, ...

  5. Java进阶(三十二) HttpClient使用详解

    Java进阶(三十二) HttpClient使用详解 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们 ...

  6. SQL注入之Sqli-labs系列第三十二关(基于宽字符逃逸注入)

    开始挑战第三十二关(Bypass addslashes) 0x1查看源代码 (1)代码关键点 很明显,代码中利用正则匹配将 [ /,'," ]这些三个符号都过滤掉了 function che ...

  7. 《手把手教你》系列技巧篇(三十二)-java+ selenium自动化测试-select 下拉框(详解教程)

    1.简介 在实际自动化测试过程中,我们也避免不了会遇到下拉选择的测试,因此宏哥在这里直接分享和介绍一下,希望小伙伴或者童鞋们在以后工作中遇到可以有所帮助. 2.select 下拉框 2.1Select ...

  8. Bootstrap <基础三十二>模态框(Modal)插件

    模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 如果您想要单独引用该插件的功能,那么您需要引用  ...

  9. COJ968 WZJ的数据结构(负三十二)

    WZJ的数据结构(负三十二) 难度级别:D: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个点的无根树,边上均有权值,每个点上有 ...

随机推荐

  1. jQuery Mobile 和 Kendo UI 的比较(转)

    jQuery Mobile 和 Kendo UI 的比较 转自 https://www.oschina.net/translate/jquery-mobile-versus-kendo-ui?cmp ...

  2. python 同时迭代多个序列

    每次分别从一个序列中取一个元素 >>> xpts = [1, 5, 4, 2, 10, 7] >>> ypts = [101, 78, 37, 15, 62, 99 ...

  3. 简单理解offsetleft、offsetTop、offsetParent

    先来看看offsetParent返回的是什么值 ele.offsetParent返回的是ele元素最近的并且是定位过(relative,absolute)的父元素,如果没有父元素或者是父元素中没有一个 ...

  4. mustache使用

    mustache模板,用于构造html页面的内容, 前端html代码: <select name="itemtype" id="itemtype" cla ...

  5. j2ee分布式缓存同步实现方案dlcache v1.0.1

    j2ee分布式缓存同步实现方案dlcache v1.0.1 发布 修复问题: 1.支持两个层次的缓存,典型的用于产品大类.产品小类,数据字典以及子项: 更新后见: pan http://pan.bai ...

  6. Win10 Ubuntu 双系统 卸载 Ubuntu

    Win10 Ubuntu 双系统 卸载 Ubuntu 其实卸载 Ubuntu 系统很简单,进 win10 系统之后,磁盘管理,格式化 Ubuntu 的磁盘就可以了. 但是最费劲的是什么呢? 就是格式化 ...

  7. linux内核分析 第3章读书笔记

    第三章 进程管理 一.进程 1.进程 进程就是处于执行期的程序. 进程就是正在执行的程序代码的实时结果. 进程是处于执行期的程序以及相关的资源的总称. 进程包括代码段和其他资源. 2.线程 执行线程, ...

  8. 自定义鼠标右键(层叠式菜单:cascading menu)(文件系统右键、文件夹系统右键和桌面鼠标右键)

    转载:http://www.cnblogs.com/killerlegend/p/3575391.html 转载:http://www.cnblogs.com/shouce/p/5101001.htm ...

  9. win7下把电脑设置成wlan热

    有很多公司没有无线网,只有自己的电脑可以上网,现在设置热点,可以手机上网 步骤: 1.看自己的网卡是否支持承载网络,如果不支持,本法就不适用 在CMD里用    netsh wlan show dri ...

  10. 乘积尾零|2018年蓝桥杯B组题解析第三题-fishers

    标题:乘积尾零 如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零? 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 ...