search

Home  >  Q&A  >  body text

What do post get_results in ci framework each return?

Modify a system online and offline. Novices cannot understand this ci framework. . . I don't know how to change it to achieve my function.

public function getImagesById88() {
        $v  = array(); 
        $id = intval($this->input->post('id',TRUE));
        $list = $this->mysql_model->get_results(contract_IMG,'(invId='.$id.') and isDelete=0');
        foreach ($list as $arr=>$row) {
            $v[$arr]['pid']          = $row['id'];
            $v[$arr]['status']       = 1;
            $v[$arr]['name']         = $row['name'];
            $v[$arr]['url']          = site_url().'/basedata/inventory/getImage88?action=getImage88&pid='.$row['id'];
            $v[$arr]['thumbnailUrl'] = site_url().'/basedata/inventory/getImage88?action=getImage88&pid='.$row['id'];
            $v[$arr]['deleteUrl']    = '';
            $v[$arr]['deleteType']   = '';
        }
        $data['status'] = 200;
        $data['msg']    = 'success';
        $data['files']  = $v;
        die(json_encode($data));  
    }
``
JS代码:
initDom: function() {
            var b = a.api.data || {};
            b.id && Public.ajaxPost("../basedata/inventory/getImagesById88", {
                id: b.id
            }, function(b) {
                200 == b.status ? a.addImgp(b.files) : parent.parent.Public.tips({
                    type: 1,
                    content: "获取商品图片失败!"
                })
            })
        },

我改的是传入的id值,本来只是数字,后来需要改成带有字母的,intval就变成0了。
感激不尽!


世界只因有你世界只因有你2775 days ago1007

reply all(3)I'll reply

  • 学习ing

    学习ing2017-07-05 09:46:32

    If you want to change the id to a non-number, remove the intval, and then add single quotes to the variable $id in the sql in the second parameter of get_results

    public function getImagesById88() {
            $v  = array(); 
            $id = $this->input->post('id',TRUE);
            $list = $this->mysql_model->get_results(contract_IMG,'(invId=\''.$id.'\') and isDelete=0');
            foreach ($list as $arr=>$row) {
                $v[$arr]['pid']          = $row['id'];
                $v[$arr]['status']       = 1;
                $v[$arr]['name']         = $row['name'];
                $v[$arr]['url']          = site_url().'/basedata/inventory/getImage88?action=getImage88&pid='.$row['id'];
                $v[$arr]['thumbnailUrl'] = site_url().'/basedata/inventory/getImage88?action=getImage88&pid='.$row['id'];
                $v[$arr]['deleteUrl']    = '';
                $v[$arr]['deleteType']   = '';
            }
            $data['status'] = 200;
            $data['msg']    = 'success';
            $data['files']  = $v;
            die(json_encode($data));  
        }

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-05 09:46:32

    intval is a variable converted to an integer type. The default is decimal. If your ID has changed to a letter, it is not suitable to use this

    reply
    0
  • 黄舟

    黄舟2017-07-05 09:46:32

    Please read the CI manual first, it explains it very clearly.
    get_results should be encapsulated by itself. I have never seen this framework method.

    reply
    0
  • Cancelreply