Welcome Guest, Not a member yet? Register   Sign In
Any idea why my method isn't returning TRUE?
#1

[eluser]esset[/eluser]
Hi

I have an XML-document I read in from my controller to my model which makes the insert into the DB. The insert call returnes TRUE but it doesn't return it back to the controller, then it's empty. Any ideas why? Thank you so much.


Controller
Code:
function _add_shows($shows)
    {
        // Shows
        foreach($shows->show as $node)
        {
            $result = $this->Show_model->add($node);

            if($result == TRUE)
            {
                echo '<b style="color: green;">Show added:</b> '. $node->showname . '<br/>';
            } else {
                echo '<b style="color: red;">Show not added:</b> '. $node->showname . '<br/>';
            }
        }
    }

Model
Code:
function add($show) {
        
        if( !$this->check_if_show_exists($show->showid) )
        {
            // Data
            $data = array(
                    'id'     => $show->showid,
                    'name'     => xml_convert($show->showname),
                    'link'     => xml_convert($show->showlink)
                    );
                    
            // Insert
            $result = $this->db->insert('shows', $data);
            
            return TRUE;
            
        } else {
        
            return FALSE;
        }
    }
    
    // --------------------------------------------------------------------
    
    /*
     * Check if show ID exists
     */
    function check_if_show_exists($id = '')
    {
        if ($id == '')
        {
            // no id, return false
            return FALSE;
        }

        $this->db->select('id');
        $this->db->where('id', $id);
        $result = $this->db->get('shows');

        if ($result->num_rows() != 1)
        {
            // no match, return false
            return FALSE;
        }
        else
        {
            //match, return true
            return TRUE;
        }
    }


Messages In This Thread
Any idea why my method isn't returning TRUE? - by El Forum - 04-04-2010, 06:23 AM
Any idea why my method isn't returning TRUE? - by El Forum - 04-04-2010, 11:37 AM
Any idea why my method isn't returning TRUE? - by El Forum - 04-04-2010, 11:43 AM
Any idea why my method isn't returning TRUE? - by El Forum - 04-04-2010, 02:00 PM
Any idea why my method isn't returning TRUE? - by El Forum - 04-04-2010, 02:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB