Jump to content

I'm so Lost...How to Compare and Insert Using PHP & MySQL


soma56

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.