From here you need to take id (A_I)

and from here you need to take id (A_I

Embed here

Tried through INSERT INTO ... data turns out to shove but goes as in 3 photos (First, fill 1 bar and then another)

The code that I did

 $stmt= $pdo->prepare(" INSERT INTO `cuisines` ( `name` ) VALUES ( :name ) "); foreach ($cuisines as $cuisine) { $stmt->execute([ ':name'=> $cuisine ]); $last_id = $pdo->lastInsertId(); $sql = "INSERT INTO restaurants_cuisines (id_cuisine) VALUES ($last_id)"; $pdo->exec($sql); } $stmt = $pdo->prepare(" Insert INTO `restaurants` ( `name`, `link`, `price_min`, `price_max`, `worktime`, `address` ) VALUES ( :name, :link, :price_min, :price_max, :worktime, :address ) "); foreach ($globalRests as $rest){ $stmt->execute([ ':name' => $rest['name'], ':link' => $rest['link'], ':price_min' => $rest['price']['price_min'], ':price_max' => $rest['price']['price_max'], ':worktime' => $rest['worktime'], ':address' => $rest['address'] ]); $last_id = $pdo->lastInsertId(); $sql = "INSERT INTO restaurants_cuisines (id_restaurant) VALUES ($last_id)"; $pdo->exec($sql); } 
  • It is not clear what you are trying to achieve. but in order for the data to sit in several columns in one record, they must be written in one insert operation - Mike
  • Yes, I just need it. but how to implement it I can not understand @Mike. since I have 2 foreach in the code - aldoniq
  • 2 you 2 foreach because 2 data sets. You need to decide on what principle to combine the information from these 2 arrays. for example, if they have the same number of records and their data must go parallel, then convert foreach to regular for and read the element number from both arrays. Well, or if relations are more complicated, think up logic for which element of the first array which data to take from the second - Mike

0