Jump to content

Compare tables and update 2nd table with new value


cobusbo
Go to solution Solved by Barand,

Recommended Posts

Hi I'm trying to compare two tables with each other and update the 2nd table with the new updated name from table 1 via their unique identical ID

$resultus = mysql_query("SELECT * FROM Users2");

        $rowus = mysql_fetch_array($resultus);
         $naamus = urldecode($rowus['Username']);
         $mxitus = $rowus['mxitid'];
$resultnup = mysql_query("SELECT * FROM pm");

        $rownup = mysql_fetch_array($resultnup);
         $naamup = $rownup['username'];
         $ipup = $rownup['ip'];

while($ipup == $mxitus){

$updatename = "UPDATE pm SET username= \"$naamus\" WHERE ip = \"$mxitus\"";
    mysql_query($updatename) or die("Error: ".mysql_error());
}

The $mxitus and $ipup is the 2 fields that would be identical in both tables now Im trying to update the pm table username field with the naamus field from Users 2 any assistance please?

Link to comment
Share on other sites

UPDATE pm
INNER JOIN Users2 u ON pm u.mxitid = pm.ip
SET pm.username = u.username

I tried it

$updatename = "UPDATE pm
INNER JOIN Users2 u ON pm u.mxitid = pm.ip
SET pm.username = u.Username";
    mysql_query($updatename) or die("Error: ".mysql_error());

getting error

 

 

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'u.mxitid = pm.ip SET pm.username = u.Username' at line 2
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.