Thank you very much for the help. I imagine a site like this can get flooded w/ newbies such as myself w/ such elementary questions which prob is somewhat a distraction to those wanting to engage in more advanced discussion. Maybe the site could have a beginner's corner
So I really appreciate the help.
Unfortunately after fiddling w/ it some more for what seems like several hours, I still don't seem to grasp the protocol/syntax of the language (only my 2nd day) enough to seem to put together the proper code to make this work. I've spent quite a bit of time browsing online documents/tutorials etc. While they have been immensely helpful getting started, the examples seem to either be too basic or too advanced.
Yes, sorry didn't make that clear. In this particular application, I would like the entire "car_color" column to be updated/replaced with the associated "fav_color"
I've tried both:
mysql_query("UPDATE `cars`
SET `cars`.`car_color` = `friends`.`fav_color`
JOIN `friends` ON
`friends`.`name` = `cars`.`name`");
as well as:
msql_query("UPDATE `cars`
SET `car_color` = (
SELECT `fav_color`
FROM `friends`");
but neither of them seemed to change the car_color column. Not sure what am doing wrong. My results never seem to get updated when I try to bridge the 2 tables by updating car_color w/ fav_color:
Is it a problem that both tables contain a column with the same name? (i.e. cars.name and friends.name) I didn't realize this until now. prob doesn't make a difference just bad practice.
I keep going back to my original code in 1st post:
And this line appears to be what is holding me up as all the necessary information seems cached in the arrays.
"UPDATE cars SET $row['car_color'] = $row['fav_color']";
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),....
and some other syntax errors as I fumble w/ the language protocols. and that particular line.
EDIT:
Have cleaned up the first post code a bit and wanted to post it again. I've added the line mysql_query("UPDATE car_color SET car_color = 'ugly color'"); line so as to have some reassurance that the UPDATE function was being used properly.
mysql_query("UPDATE car_color SET car_color = 'ugly color'");
$result = mysql_query("SELECT friends.name, friends.fav_color, cars.car_color ".
"FROM friends, cars ".
"WHERE friends.name = cars.name")
or die(mysql_error());
while($row = mysql_fetch_array($result)){
// mysql_query("UPDATE cars SET $row['car_color'] = $row['fav_color']");
// print out to confirm updates
echo $row['name']. ": ". '</br>' .
'fav color = ' . $row['fav_color'] . '</br>' .
'car color = ' . $row['car_color'] . '<P>';
}
?>
Outputs as:
Cathy:
fav color = Pink
car color = ugly color
John:
fav color = Blue
car color = ugly color
Marie:
fav color = Black
car color = ugly color