Redundant Insert helpage :)

Discussion in 'MySQL' started by Dirty-Rockstar, Sep 20, 2008.

  1. #1
    Im cleaning up the source of a project I did. Learning php/mysql as I go. I realized with select you can select more then one table. (duh -_-) tablea.field1,tableb.field2 etc. You old schoolers know what i mean. I think with update you can as well.

    But can this be done with Insert?

    
    $sql="INSERT INTO table1 (f1, f2, f3)VALUES('$1', '$2', '$3')" or die(mysql_error());
    $query=mysql_query($sql);
    
    $sql="INSERT INTO table2 (f1, f2, f3)VALUES('$1', '$2', '$3')" or die(mysql_error());
    $query=mysql_query($sql);
    
    PHP:
    Have that in one? I cant see how its possible and google is not telling me much. I did try for about an hour. Im tired now. Any help is appreciated
     
    Dirty-Rockstar, Sep 20, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    It also can be done with the insert as well e.g.
    $sql="INSERT INTO table1 (f1, f2, f3)VALUES('$1', '$2', '$3'), ('$1', '$2', '$3')";
    $query=mysql_query($sql) or die(mysql_error());
    PHP:
     
    mwasif, Sep 20, 2008 IP
  3. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3

    do you mean


    $sql="INSERT INTO table1,table2 (f1, f2, f3),(f1, f2, f3)VALUES('$1', '$2', '$3'), ('$1', '$2', '$3')";
    $query=mysql_query($sql) or die(mysql_error());
    PHP:
    I think you do. woot. makes things alot easier and cleaner. thanks
     
    Dirty-Rockstar, Sep 20, 2008 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    I inserted it only to one table. I never tried your way.
     
    mwasif, Sep 20, 2008 IP