php+sql 从一张表中查询出来的字段值添加到另一张的表中以及批量循环添加数据
$message=$result['message']; // $ware_house_name = array_column($message,'WarehouseCode'); // $ware_house_name=array_unique($ware_house_name); // $new_array=array_filter($ware_house_name); // //009,001,005,007,003,010,002,008 // $string=implode(',',$new_array); // $query = $DB->prepare(" // SELECT // location_id, // location_code, // location_name // FROM asset_location // WHERE location_code // IN ($string) // "); // //$string='003'; // //$query->bindvalue(':params',$string); // if (!$query->execute()) { // Flight::error(new RuntimeException(errorInfo($query))); // } elseif ($query->rowcount()== 0) { // Flight::notFound(); // } // $items = []; // // 请求到了库房的数据 // while ($row = $query->fetch(PDO::FETCH_OBJ)) { // $items[] = $row; // } // $str=''; // foreach($items as $val){ // $str+= $val->location_code; // $new_str=$str; //} $query = $DB->prepare(" INSERT INTO sp_list( sp_code, sp_name, sp_current_quantity, sp_specification, sp_unit, sp_location_id ) SELECT :sp_code, :sp_name, :sp_current_quantity, :sp_specification, :sp_unit, t.location_id FROM asset_location t WHERE t.location_code = :code ; "); foreach ($message as $row){ $sp_code=$row->InventoryCode; $sp_name=$row->InventoryName; $sp_current_quantity=$row->ExistingQuantity; $sp_specification=$row->Specification; $sp_unit=$row->UnitName; $code=$row->WarehouseCode; $query->bindvalue(":sp_code",$sp_code ); $query->bindvalue(":sp_name",$sp_name ); $query->bindvalue(":sp_current_quantity",$sp_current_quantity ); $query->bindvalue(":sp_specification",$sp_specification ); $query->bindvalue(":sp_unit",$sp_unit ); $query->bindvalue(":code",$code ); $query->execute(); } if (!$query->execute()) { Flight::error(new Exception(errorInfo($query))); } $new_id = $DB->lastInsertId();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现