我的查询只是在插入UPDATE
中更新jobResponsibilities
字段,但我想
在一条记录中插入所有值,例如不仅 j 。table_2
jobResponsibilities = c00017
jobResponsibilities = C00001,C00302,C00303,C00287,C00286,C00285,C00017
obResponsibilities = C00017
我的代码如下:
function mySQLSafe( $value, $quote = "'"){
// strip quotes if already in
$value = get_magic_quotes_gpc() ? stripslashes($value) : $value;
$value = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($value) : mysql_escape_string($value);
// Stripslashes
if (get_magic_quotes_gpc()){
$value = stripslashes($value);
}
// Quote value
if (version_compare(phpversion(), "4.3.0") == "-1") {
$value = mysql_escape_string($value);
} else{
$value = mysql_real_escape_string($value);
}
$value = $quote . $value . $quote;
return $value;
}
$comcode = "SELECT jobCode, compCode
FROM first_table";
$comcode_RS = mysql_query($comcode, $timespace) or die (mysql_error());
while($row_comcode_RS = mysql_fetch_assoc($comcode_RS))
{
$jobCode = $row_comcode_RS['jobCode']; // more than one record
$compCode = $row_comcode_RS['compCode']; // more than one record
echo $updateSQL = "UPDATE second_table SET jobResponsibilities=".mySQLSafe($compCode)." WHERE jobCode=".mySQLSafe($jobCode)."";
$Result1 = mysql_query($updateSQL, $timespace) or die(mysql_error());
}