Welcome Guest, Not a member yet? Register   Sign In
Trying to pass variable from 1 Function to Another to Put in Array within same Model
#11

[eluser]jshultz[/eluser]
Ok, changed 'query' to 'id' and also tried: 'busid'=> $bus_id[0]['id'], and neither one worked. now getting:

Error Number: 1048

Column 'busid' cannot be null

INSERT INTO `photos` (`userid`, `thumb`, `fullsize`, `busid`) VALUES ('1', '/home/welcomet/public_html/assets/images/gallery/thumbs/epic-fail-family-portraits-fail1.jpg', '/home/welcomet/public_html/assets/images/gallery/epic-fail-family-portraits-fail1.jpg', NULL)

(I'm just uploading random photos for testing)
#12

[eluser]D.Phil[/eluser]
Here try these modifications:

function get_bus_id()
Code:
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);
    $this->db->limit(1);
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        $row = $query->row();
        return $row->id();
    } else return false;
}

function do_upload()
Code:
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,
    );
    
    echo var_dump($bus_id);
    
    $this->db->insert('photos', $data);
}
#13

[eluser]vitoco[/eluser]
again....some echos

try this and see the data
Code:
$upload = $this->upload->data();
        $bus_id = $this->get_bus_id();
        // CHECK THE DATA RETURNED BY THE MODEL
        echo '<pre>'.$print_r( $bus_id , true ).'</pre>';
        
        $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'],
        );
        // CHED THE DATA CREATED FOR INSERT
        echo '<pre>'.$print_r( $data , true ).'</pre>';
        
        $this->db->insert('photos', $data);

the field in the 'photos' table is named 'busid' or 'bus_id' ?? cause the db->insert method set it to NULL....
#14

[eluser]jshultz[/eluser]
[quote author="vitoco" date="1274749382"]again....some echos

try this and see the data
Code:
$upload = $this->upload->data();
        $bus_id = $this->get_bus_id();
        // CHECK THE DATA RETURNED BY THE MODEL
        echo '<pre>'.$print_r( $bus_id , true ).'</pre>';
        
        $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'],
        );
        // CHED THE DATA CREATED FOR INSERT
        echo '<pre>'.$print_r( $data , true ).'</pre>';
        
        $this->db->insert('photos', $data);

the field in the 'photos' table is named 'busid' or 'bus_id' ?? cause the db->insert method set it to NULL....[/quote]

The field in the photos table is called id.

I also got Undefined variable: print_r

Fatal error: Function name must be a string in /home/welcomet/public_html/application/models/gallery_model.php on line 44

which was:

echo '<pre>'.$print_r( $bus_id , true ).'</pre>';
#15

[eluser]D.Phil[/eluser]
That's because you don't need a dollar sign before print_r

[quote author="jshultz" date="1274749792"]
I also got Undefined variable: print_r

Fatal error: Function name must be a string in /home/welcomet/public_html/application/models/gallery_model.php on line 44

which was:

echo '<pre>'.$print_r( $bus_id , true ).'</pre>';[/quote]
#16

[eluser]vitoco[/eluser]
can you post the structure of the 'photos' table ???
#17

[eluser]jshultz[/eluser]
Sure, it's:

PHOTOS is the table that photos are being added to:
id, the row ID
photoname
thumb
fullsize
busid
userid

get_bus_id is getting the id from the BUSINESS table:
id,
busname
busowner
busaddress
buscity
busstate
buszip
busphone
webaddress
category
featured
userid


get_bus_id queries the business table, matching userid that is stored in a cookie with userid that is in the table. it then spits back out id which is the unique id for the business.
#18

[eluser]vitoco[/eluser]
my mistake ...was print_r , not $print_r , try this
Code:
$upload = $this->upload->data();
        $bus_id = $this->get_bus_id();
        // CHECK THE DATA RETURNED BY THE MODEL
        echo '<pre>'.print_r( $bus_id , true ).'</pre>';
        
        /*
        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(),
        );
        // CHED THE DATA CREATED FOR INSERT
        echo '<pre>'.print_r( $data , true ).'</pre>';
        
        $this->db->insert('photos', $data);
#19

[eluser]jshultz[/eluser]
I only got one array output it looks like:

Array
(
[userid] => 1
[thumb] => /home/welcomet/public_html/assets/images/gallery/thumbs/fail-owned-snowboard-fail.jpg
[fullsize] => /home/welcomet/public_html/assets/images/gallery/fail-owned-snowboard-fail.jpg
[busid] =>
)

I tried twice and couldn't get $bus_id. i even tried it with it being the only print_r statement and nothing came out.
#20

[eluser]D.Phil[/eluser]
Can you post both functions again on pastebin or something




Theme © iAndrew 2016 - Forum software by © MyBB