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. Link to comment https://forums.phpfreaks.com/topic/213451-im-so-losthow-to-compare-and-insert-using-php-mysql/ 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. Link to comment https://forums.phpfreaks.com/topic/213451-im-so-losthow-to-compare-and-insert-using-php-mysql/#findComment-1111235 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 Link to comment https://forums.phpfreaks.com/topic/213451-im-so-losthow-to-compare-and-insert-using-php-mysql/#findComment-1111245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.