I've created this simplified version of a problem I can't seem to tackle by searching/reading online documents alone.
Basically I want to replace some field in a table, to that of a field in another table.
the 2 tables are called "friends" and "cars"
their common column is called "name"
table friends has a column "fav_color"
table cars has a column "car_color"
I want to update car_color w/ fav_color.
Can't seem to find the right syntax for the use of the Update function? Am I even using it correctly?
<?php
... connect to database
$query = "SELECT friends.name, friends.fav_color, cars.car_color ".
"FROM friends, cars ".
"WHERE friends.name = cars.name";
$result = mysql_query($query)
or die(mysql_error());
while($row = mysql_fetch_array($result)){
//UPDATE tablename SET (fieldname1=value1,fieldname2=value2,...) WHERE fldstudid=IdNumber <- syntax according to online documents?
"UPDATE cars SET ( $row['car_color'] = $row['fav_color'])";
// print out to confirm updates
echo $row['name']. ": ". $row['fav_color'] . " = " . $row['car_color'];
echo "<br />";
}
?>
thnx for any help in advance
EDIT:
Sorry just read the stickied guideline for posting and prob didn't supply enough info:
* Not sure what version of php (am using a relatively new version of Easyphp for offline/local host)
* have tried various different ways to write that Update line, but seem to always get a syntax error.
hope that fits some of the quidelines for question.
Edited by bajadulce, 08 January 2013 - 04:44 PM.











