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

[eluser]earlyriser[/eluser]
Dready: thanks for your reply.
I tried your code as you can see below, but I only got a blank page. Any advice?

Code:
function comment_insert()
    {
        //check if the wine is in database
        $this->db->select('*');
        $this->db->from('wines');
        $this->db->where('name', $_POST['name']);
        $data['query']= $this->db->get();
        if ($query->num_rows() > 0) //if it was found in wines.name
        {
            $dbrow = $query->row_array();
            $wine_id = $dbrow['id'];
        }
        else    //if it wasnt found in wines.name
        {
            $this->db->insert('wines',array('name'=>$_POST['name'],'year'=>$_POST['year']));
            $wine_id = $this->db->insert_id();            
        }
        //insert 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-02-2008, 02:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB