Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更新mysql中两个不同表中的相同批处理id?_Php - Fatal编程技术网

Php 如何更新mysql中两个不同表中的相同批处理id?

Php 如何更新mysql中两个不同表中的相同批处理id?,php,Php,我正在用这个。。。 请帮助我。您可以使用存储过程来完成此操作-在事务中使用update语句编写存储过程。或者像这样编写查询 编辑: $save= mysql_query("update students set bid=(select bid from batches where batches.start_date=students.start_date)"); 写上述内容的更好方法是 UPDATE students s, anothertable a SET s.bid = (

我正在用这个。。。
请帮助我。

您可以使用存储过程来完成此操作-在事务中使用update语句编写存储过程。或者像这样编写查询

编辑:

$save= mysql_query("update students set bid=(select bid from batches 
    where batches.start_date=students.start_date)"); 
写上述内容的更好方法是

UPDATE students s, anothertable a
SET s.bid = (select bid from batches 
where batches.start_date=students.start_date),a.bid = (select bid from batches 
where batches.start_date=students.start_date)
尝试:


我不明白你想做什么只是解释你的意图从批次中选择出价。开始日期=学生。开始日期可以返回多个结果…..是的..我想返回多个结果实际上有4种类型的课程,即android、testing、.net、iPhone。。。。当我选择这些选项中的任何一个来创建新的学生注册时,数据必须插入到数据库中,所有字段都在插入,但这些bid显示为null。因此,批次id应该与学生id相同。。这里学生是一张桌子,批次是另一张桌子。我想把那两张桌子连接起来。请帮助我获取您需要在where batches中而不是在where batches中使用的多个结果。start_date=students.start_date您需要在where batches.start_date中使用students.start_date我尝试了此操作,但bid显示为null,它没有插入到数据库中。您的batches表包含字段bid?您的查询有错误吗?
UPDATE students s, anothertable a, batches b
SET s.bid = b.bid, a.bid = b.bid 
where b.start_date=s.start_date;
update students  join batches  
on batches.start_date=students.start_date 
set students.bid=batches.bid