我要做的是更新具有相同id的多行mysql表。我搜索了许多解决方案,但无法找到合适的解决方案。我的桌子看起来像下面这样:
$fname = $_POST['fname'];
mysql_query("INSERT INTO applicants ($fname) VALUES ('$fname')");
所以我想更新此表+----+--------+--------+--------------+----------+
| id | emp_id | job_id | basic_salary | stat |
+----+--------+--------+--------------+----------+
| 62 | 186 | 30 | 8400 | Active |
| 64 | 110 | 8 | 12542 | Inactive |
| 65 | 110 | 5 | 12542 | Active |
+----+--------+--------+--------------+----------+
和id = 64
作为emp_id = 110
,如果Active
emp_id 110
Inactive
Active
,则emp id 110
{1}}以便active
只有一条记录保持inactive
而其余{{1}}。
请您帮忙。
答案 0 :(得分:1)
可以尝试这些简单的查询: -
internal
然后:
UPDATE <table_name> SET `stat` = "Active" WHERE id = 64 AND emp_id = 110
答案 1 :(得分:1)
你可以这样做
// first find all the records for the employee with status as Active and make them Inactive.
$query1 = mysql_query("select * from table_employee where emp_id = 110 and status = 'Active' ");
if($query1 && mysql_num_rows($query1) > 0)
{
while(mysql_fetch_array($query1))
{
mysql_query("update table_employee set status = 'Inactive' where emp_id = 110");
}
}
// then make the record Active that you you want to
$query2 = mysql_query("update table_employee set status = 'Active' where emp_id = 110 and id = 64");
答案 2 :(得分:0)
您可以尝试的一件事是将活动ID存储在布尔值中(如果您正在改变表格方案)。然后,您可以通过搜索员工ID和布尔值true来检查活动。