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); }
foreach
in the code - aldoniq