English 中文(简体)
在相同的模型中将1个功能变数改为Put
原标题:Trying to pass variable from 1 Function to Another to Put in Array within same Model

这真是混淆不清。 我试图这样做的是。 我先把照片上载到服务器。 它向非行铺设道路。 我需要将生意的补贴附在光灯上。

这里我迄今为止所做的事情:

function get_bus_id() {
    $userid = $this->tank_auth->get_user_id();
    $this->db->select( b.id );
    $this->db->from ( business AS b );
    $this->db->where ( b.userid , $userid);
    $query = $this->db->get();
        if ($query->num_rows() > 0) {
          // RESULT ARRAY RETURN A MULTIDIMENSIONAL ARRAY e.g. ARRAY OF DB RECORDS
          // ( ROWS ), SO IT DOENS T FIT
          //return $query->result_array();
          // THE CORRECT METHOD IS row_array(), THAT RETURN THE FIRST ROW OF THE 
          // RECORDSET
          $query->row_array();
            }

这得到企业的id。 然后,我有上载功能,如下:

/* Uploads images to the site and adds to the database. */
    function do_upload() {

        $config = array(
             allowed_types  =>  jpg|jpeg|gif|png ,
             upload_path  => $this->gallery_path,
             max_size  => 2000
        );

        $this->load->library( upload , $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        $config = array(
             source_image  => $image_data[ full_path ],
             new_image  => $this->gallery_path .  /thumbs ,
             maintain_ratio  => true,
             width  => 150,
             height  => 100
        );

        $this->load->library( image_lib , $config);
        $this->image_lib->resize();

        $upload = $this->upload->data();
        $bus_id = $this->get_bus_id();

        $data = array(
             userid  => $this->tank_auth->get_user_id(),
             thumb  => $this->gallery_path .  /thumbs/  . $upload[ file_name ],
             fullsize  => $upload[ full_path ],
             busid => $bus_id[ id ],
        );

        echo var_dump($bus_id);

        $this->db->insert( photos , $data);
    }

我忘记的问题是:

A PHP Error

严重程度:通知

讯息:不明确的指数:id

档案名称:模型/加勒y_model.php

电话:48

我先尝试了获得价值的各种途径,但我的有限知识却不断发展。 任何帮助都会得到真正的赞赏。

问题回答

勿庸置疑,不提“回答”。

第48条的内容是什么? 哪一个文件是Gallery_model.php? 从该数据库的音响来看,它可能是一阵列钥匙,尚未启动,或是查询数据库的问题。

问题是,如果找不到生意,你的职能就不会恢复。 因此,<代码>$bus_id在其中没有任何(甚至没有阵列)。 您或许应当有您的<代码>get_bus_id()功能退回,如:

        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }

其后,在您打电话get_bus_id()之后,您可核对$bus_id = 虚假,并可能退回错误,以表示从do_upload()<

奥基,我工作。 这是一部完整和可行的法典:

/* Uploads images to the site and adds to the database. */
    function do_upload() {

        $config = array(
             allowed_types  =>  jpg|jpeg|gif|png ,
             upload_path  => $this->gallery_path,
             max_size  => 2000
        );

        $this->load->library( upload , $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        $config = array(
             source_image  => $image_data[ full_path ],
             new_image  => $this->gallery_path .  /thumbs ,
             maintain_ratio  => true,
             width  => 150,
             height  => 100
        );

        $this->load->library( image_lib , $config);
        $this->image_lib->resize();

        $upload = $this->upload->data();
        $bus_id = $this->get_bus_id();

        /*
        TABLE STRUCTURE =============
            id, the row ID
            photoname
            thumb
            fullsize
            busid
            userid
        */



        $data = array(
             id         => 0 , // I GUESS IS AUTO_INCREMENT
             photoname     =>   ,
             thumb         => $this->gallery_path .  /thumbs/  . $upload[ file_name ],
             fullsize     => $upload[ full_path ],
             busid => $bus_id[ id ],
             userid  => $this->tank_auth->get_user_id(),
        );

        // CHECK THE DATA CREATED FOR INSERT

        $this->db->insert( photos , $data);
    }

/ Get Business ID from theDB

function get_bus_id() {
        $userid = $this->tank_auth->get_user_id();
        $this->db->select( b.id );
        $this->db->from ( business AS b );
        $this->db->where ( b.userid , $userid);
        $query = $this->db->get();
            if ($query->num_rows() > 0) {
              // RESULT ARRAY RETURN A MULTIDIMENSIONAL ARRAY e.g. ARRAY OF DB RECORDS
              // ( ROWS ), SO IT DOENS T FIT
              //return $query->result_array();
              // THE CORRECT METHOD IS row_array(), THAT RETURN THE FIRST ROW OF THE
              // RECORDSET
              return $query->row_array();
            }
        }




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签