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.

Link to comment
Share on other sites

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