-4
update new_calls_display set city_id = '3' where cus_city like '%Madurai%'

above mysql query i want to change the city_id value dynamically and also corresponding cus_city also change dynamically from the current table(new_calls_display) using php coding

city_id             cus_city
1                Chennai
2                Ariyalur
2                Ariyalur
3                Madurai
3                Madurai
3                Madurai
1                Chennai
1                Chennai

like above table cus_id 1 to 50 so cus_city also 50 unique values

4

2 回答 2

0

您需要使用一个变量,然后将其连接到 sql 查询字符串:

$idcity = 2;

"update new_calls_display set city_id = {$idcity} where cus_city like '%Madurai%'"

不要忘记照顾 sql 注入,以前的代码可以轻松破解。

于 2012-10-16T12:17:14.640 回答
0
update new_calls_display 
set city_id = (
select  col_name from table_name where cus_city like '%Madurai%'   )
于 2012-10-16T12:18:50.240 回答