Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]How to make a conditional insert in multiple tables?
#14

[eluser]earlyriser[/eluser]
It works now.
I replaced the line
$data['query']= $this->db->get();
by
$result = $this->db->get();
But I am not sure why this was necessary. Could you help me to grasp that?

Then the view is the same and the controller code is
Code:
function comment_insert()
    {
        //check if the wine is in database
        $thename=$_POST['name'];
        $this->db->select('*');
        $this->db->from('wines');
        $this->db->where('name', $thename);
        $result = $this->db->get();    // <-- SOLUTION
        
         if ($result->num_rows() > 0) //if the wine is old, retrieve id
        {
            $dbrow = $query->row_array();
            $wine_id = $dbrow['id'];
        }
        else    //if the wine is old, add it
        {
            $this->db->insert('wines',array('name'=>$_POST['name'],'year'=>$_POST['year']));
            $wine_id = $this->db->insert_id();            
        }
        //finally insert wine comment
        $this->db->insert('wine_comments',array('user_id'=>$_POST['user_id'],'wine_id'=>$wine_id,'rating'=>$_POST['rating']));  
    }


Messages In This Thread
[SOLVED]How to make a conditional insert in multiple tables? - by El Forum - 10-03-2008, 10:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB