soma56 Posted September 15, 2010 Share Posted September 15, 2010 I'm still in diapers when it comes to MySQL so here goes nothing.... The logic is simple compare tbl1 value 1 with tbl2 value 1 and if there is a match then drop tbl1 value 2 into tble2 value 2 But before that the names between tbl1 value 1 and tbl2 value 1 are backwards (last name first) so I've reversed them in the first table. I've got to the point where I can actually insert into the database but instead of placing the new data where I need it (right beside where the comparison was made) I get a bunch of new rows. <?PHP include "dbconnect.php"; $result = mysql_query("SELECT * FROM players"); while($row = mysql_fetch_array($result)){ if(empty($row['player_position'])){ $fullname = $row['player_name']; $pieces = explode(" ", $fullname); $splitname = $pieces[1]. " " .$pieces[0]; $key = addslashes($splitname); $query2 = "SELECT * FROM players_scrape WHERE player_name LIKE '%$key%'"; $result2 = mysql_query($query2) or die(mysql_error()); while($row = mysql_fetch_array($result2)){ $playerposition = $row['player_position']; mysql_query("INSERT INTO players (test) VALUES ('$playerposition') "); } } } ?> I really hope someone can help me with this. Quote Link to comment Share on other sites More sharing options...
trq Posted September 15, 2010 Share Posted September 15, 2010 I've got to the point where I can actually insert into the database but instead of placing the new data where I need it (right beside where the comparison was made) I get a bunch of new rows. You would need to UPDATE the existing row, not INSERT into a new one. Quote Link to comment Share on other sites More sharing options...
soma56 Posted September 15, 2010 Author Share Posted September 15, 2010 Thanks Tibor. I managed to do it with the following: mysql_query("UPDATE players SET test='$myvar' WHERE player_name='$splitname'"); It only took an hour Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.