我的代码有问题,问题是数据未更新仍然为 NULL。
表A
year | period | code | user_id
2013 | 4 | 1231 |
2013 | 4 | 1232 |
2013 | 4 | 1233 |
2013 | 4 | 1234 |
2013 | 4 | 1235 |
表 B
user_id | user_name | cash
A1 | AB | 10
A2 | BC | 5
A3 | CD | 7
当现金> = 7时,我会将表B user_id放入表A user_id
表格结果
year | period | code | user_id
2013 | 4 | 1231 | 10
2013 | 4 | 1232 | 7
2013 | 4 | 1233 |
2013 | 4 | 1234 |
2013 | 4 | 1235 |
这是我的代码,
$arr = array();
$query = mysql_query("select user_id from tableB where cash >= 7");
while ($arrs = mysql_fetch_array($query)) {
$arr[] = $arrs[0];
}
$count = count($arr);
for ($i = 0; $i < $count; $i++) {
$sql = mysql_query("UPDATE tableA SET user_id ='$arr[$i]' WHERE year = 2013 and period = 4 and user_id IS NULL");
}
if ($sql) {
echo "success";
}