zoukankan      html  css  js  c++  java
  • legend3---14、所有增删改的前置操作可以是什么

    legend3---14、所有增删改的前置操作可以是什么

    一、总结

    一句话总结:

    先查询数据有没有,这样既起到了服务端验证的功能,也避免了很多增删改可能的错误

    1、用户收藏视频,收藏课程有必要建立用户收藏视频表和用户收藏课程表么(已经有了用户课程表和用户视频表的基础上)?

    没有必要:比如说课程,因为已经有了用户课程表,那么用户和课程的所有逻辑都可以在这个表里面,而收藏也仅仅只是一种交互逻辑

    2、视图共用模块注意?

    让标识唯一就好,共用模块里面内部的元素可以不用太区分

    3、页面中的js的注释,不要写用户可以通过网页源代码看到的注释?

    不要用//和/**/,可以用{{--课程的点赞操作--}}

    4、从数据表中获取单行或单个值?

    单行:first():DB::table('users')->where('name', 'John')->first()
    单个值:value('email'):DB::table('users')->where('name', 'John')->value('email')

    如果你只需要从数据表中获取一行数据,你可以使用 first 方法。该方法返回一个 StdClass 对象:

    $user = DB::table('users')->where('name', 'John')->first();

    echo $user->name;
    如果你甚至不需要整行数据,则可以使用 value 方法从记录中获取单个值。该方法将直接返回该字段的值:

    $email = DB::table('users')->where('name', 'John')->value('email');

    5、写了sql语句可以跑到数据库里面分析一下语句的效率?

    explain语句:explain select count(*) as aggregate from `user_questions` where `uq_u_id` = 1 and `uq_collected` = 1

    6、页面中ajax根据板块动态获取板块的数据如何实现?

    初始的时候传空数据过来就好(不用查数据库),点到哪一个,那就ajax取哪一个的数据就好

    7、SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'cl_u_id' in where clause is ambiguous (SQL:...)?

    Integrity constraint violation:完整性约束违反
    ambiguous:英 /æmˈbɪɡjuəs/:adj. 模糊不清的

    8、php对数组去重?

    array_unique()

    9、lavarel中表自己连自己?

    因为两个相同的表,所以要特别指定 要查找的字段到底是哪个里面的字段
    $lesson_comments=CommentLesson::where('pid_comment_lessons.cl_u_id',$u_id)
    ->orderBy('cl_created_at','desc')->offset($offset)->limit($per_page_item_num)
    ->join('comment_lessons as pid_comment_lessons', 'comment_lessons.cl_pid', '=', 'pid_comment_lessons.cl_id')
    ->join('users', 'pid_comment_lessons.cl_u_id', '=', 'users.id')
    ->join('lessons', 'comment_lessons.cl_l_id', '=', 'lessons.l_id')
    ->select($select_field)->get();

    10、查询用户的所有对课程的评论和回复(查询回复的话需要在where条件里面用join)?

    union操作加上表自己连自己,根据不同的情况用不同的字段连user表
    数据库里面加个to_u_id字段这样查询操作会变的简单一点
      $select_field=['comment_lessons.*','users.name','users.id','lessons.l_title','lessons.l_id'];
      //1、这是所有我发的,我回复的或者我评论的:这里我并不需要知道自己的信息
      $lesson_comments_active=CommentLesson::where('comment_lessons.cl_u_id',$u_id)
          ->join('comment_lessons as pid_comment_lessons', 'comment_lessons.cl_pid', '=', 'pid_comment_lessons.cl_id')
          ->join('users', 'pid_comment_lessons.cl_u_id', '=', 'users.id')
          ->join('lessons', 'comment_lessons.cl_l_id', '=', 'lessons.l_id')
          ->select($select_field);
    
      //2、这是所有回复我的,我需要知道用户的信息
      $lesson_comments=CommentLesson::where('pid_comment_lessons.cl_u_id',$u_id)
          ->join('comment_lessons as pid_comment_lessons', 'comment_lessons.cl_pid', '=', 'pid_comment_lessons.cl_id')
          ->join('users', 'comment_lessons.cl_u_id', '=', 'users.id')
          ->join('lessons', 'comment_lessons.cl_l_id', '=', 'lessons.l_id')
          ->union($lesson_comments_active)
          ->orderBy('cl_created_at','desc')->offset($offset)->limit($per_page_item_num)
          ->select($select_field)->get();

    11、videojs中实现过多长时间自动记录播放进度?

    用一个定时器,如果视频在播放,定时器就开始走,过三分钟就ajax到服务器
    如果暂停或者结束,也直接ajax到服务器,暂停清除定时器,再点开始的时候再重新启动定时器

    12、前端页面可以都用vue,会简单方便特别多的?

    相对于jquery+vue的ajax方式,vue的方式安全的多

    13、Non-static method IlluminateDatabaseEloquentModel::save() should not be called statically?

    $userLesson::save() 改成 $userLesson->save() 即可

    二、内容在总结中

     
  • 相关阅读:
    从留言簿开始,学习MonoRail MVC(三)
    从留言簿开始,学习MonoRail MVC(二)
    程序集版本最后一位使用SVN版本号的自动生成方法
    如何让.Net控件在设计时InitializeComponent()中不生成相关代码
    [收藏]Web Services and C# Enums
    从留言簿开始,学习MonoRail MVC(一)
    .Net控制USB设备相关内容
    .Net 2.0ListView控件在Windows 2000和Windows XP上的差异
    基于高德地图Windows Phone API 快速开发地图相关APP(二)
    android map api v2 示例 步骤及问题
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/11738774.html
Copyright © 2011-2022 走看看