php项目

最近用thinkphp5框架制作了一个家具城网站,还在制作中,就目前为止,发现了很多自身问题,诸如代码记不熟,方法不会用等,今天分享一下我遇到的问题!

一。数据库查询

    总是记不住查询语句含义如:

 $kk = db('chanpin')->find();

    最后的“find()”是查询单条数据,

$kk = db('chanpin')->select();

    而“select()”则是查询所有数据,经常记不住!

二。上传数据对接

    经常写错代码

 $arr = db('chanpin')->select();
        $this->assign('arr',$arr);
        if (request()->isPost()){
            $file = request()->file('img');
            if ($file) {
                $info = $file->validate(['size' => 15678000, 'ext' => 'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
                if ($info) {
                    // echo $info->getSaveName();
                    $where['img'] = '/uploads//' . $info->getSaveName();
                } else {
                    echo $file->getError();
                }
            }
            $a = input('post.');
            $where['name'] = trim($a['name']);
            $where['aid'] = trim($a['asa']);
            $where['jj'] = trim($a['ada']);
            $where['jg'] = trim($a['aza']);
            $where['chicun'] = trim($a['qsc']);
            $where['cailiao'] = trim($a['qaz']);
            $where['kuanshi'] = trim($a['wsx']);
            $where['yunshu'] = trim($a['edc']);
            $where['zan'] = 0;
            $b = db('chanpin')->insert($where);
            if($b){
                $this->success('上传成功');
            }
        }

    数量大,我还没有复制粘贴的习惯,经常一条条的手打。。。

<!-- 1.添加产品 -->
                <form class="layui-form layui-card-body" action="" method="POST" enctype="multipart/form-data">
                  <!-- 添加名称 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">产品名称</label>
                    <div class="layui-input-inline">
                      <input type="text" name="name" required lay-verify="required" placeholder="请输入产品名" autocomplete="off" class="layui-input">
                    </div>
                  </div>

                  <!-- 上传图片 -->
                    <input type="file" name="img">

                  <!-- 填写价格 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">填写价格</label>
                    <div class="layui-input-inline">
                      <input type="text" name="aza" id="">
                    </div>
                  </div>

                  <!-- 填写尺寸 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">填写尺寸</label>
                    <div class="layui-input-inline">
                      <input type="text" name="qsc" id="">
                    </div>
                  </div>

                  <!-- 填写材料 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">填写材料</label>
                    <div class="layui-input-inline">
                      <input type="text" name="qaz" id="">
                    </div>
                  </div>

                  <!-- 填写风格 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">填写风格</label>
                    <div class="layui-input-inline">
                      <input type="text" name="wsx" id="">
                    </div>
                  </div>

                  <!-- 运输范围 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">运输范围</label>
                    <div class="layui-input-inline">
                      <input type="text" name="edc" id="">
                    </div>
                  </div>

                  <!-- 选择分类 -->
                  <select class="selectpicker" name="asa">
                    {volist name="arl" id="vp"}
                      <option value="{$vp.id}">{$vp.name}</option>
                    {/volist}
                  </select>

                  <!-- 填写简介 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">填写简介</label>
                    <div class="layui-input-inline">
                      <textarea name="ada" id="" cols="80" rows="5"></textarea>
                    </div>
                  </div>

                  <!-- 提交数据 -->
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo" value="submit">立即提交</button>
                      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                  </div>
                </form>
上一篇:CSS父级边框塌陷问题


下一篇:js 转换为字符串方法