simultaneous updating of rows in a databse

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • backups2007
    New Member
    • Jul 2007
    • 92

    simultaneous updating of rows in a databse

    How do I simultaneously update rows of data in a database?
    Should I Update it one by one? Or is there any other way to do it?

    Code:
    $query = mysql_query("UPDATE tblProducts SET prod_code='$prod_code1'");
    if($query)
    {
    $query2 = mysql_query("UPDATE tblProducts SET prod_code='$prod_code2'");
    
    if($query2)
    {
        echo "update success!";
    }
    }
  • t0m66
    New Member
    • Oct 2007
    • 6

    #2
    Well, that code there will just set it to the last value because there is no WHERE condition. (First, it will set it to query 1's value, but then it will all be set to query 2's value). To run multiple queries in a MySQL call, you can seperate them with semicolons, but I wouldn't know why you'd want to do that.

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      Originally posted by t0m66
      To run multiple queries in a MySQL call, you can seperate them with semicolons
      I'm actually pretty sure mysql_query() can only run one query at a time. Seperating with semicolons won't work.

      From the www.php.net website:

      mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .

      Here is the link: php.net - info on mysql_query()

      Comment

      • backups2007
        New Member
        • Jul 2007
        • 92

        #4
        can't i do something like that of how inserting data is done?

        Code:
        $query = mysql_query("INSERT INTO tblProducts (product_id, description)VALUES ('prod_id1','desc1'),('prod_id2','desc2')");

        Comment

        Working...