1 回答
TA贡献1744条经验 获得超4个赞
您可以使用$link->insert_id.
$i = 1;
foreach ($games as $rounds) {
$free = "";
echo "<h5>Etapa {$i}</h5>";
$stmt = $link->prepare('INSERT INTO fixture (fixture) VALUES (?)');
$stmt->bind_param('i', $i);
$stmt->execute();
$id_fixture = $link->insert_id; // The auto generated ID
foreach ($rounds as $match) {
if ($match[0] == "stă etapa asta.") {
$free = "<span style='color:red;'>{$match[1]} {$match[0]}</span><br>";
$stmt = $link->prepare('INSERT INTO `match` (fixture, homeTeam, awayTeam) VALUES (?, ?, ?)');
$stmt->bind_param('iss', $id_fixture, $match[1], $match[0]);
$stmt->execute();
} elseif ($match[1] == "stă etapa asta.") {
$free = "<span style='color:red;'>{$match[0]} {$match[1]}</span><br>";
$stmt = $link->prepare('INSERT INTO `match` (fixture, homeTeam, awayTeam) VALUES (?, ?, ?)');
$stmt->bind_param('iss', $id_fixture, $match[0], $match[1]);
$stmt->execute();
} else {
echo "{$match[0]} vs {$match[1]}<br>";
$stmt = $link->prepare('INSERT INTO `match` (fixture, homeTeam, awayTeam) VALUES (?, ?, ?)');
$stmt->bind_param('iss', $id_fixture, $match[0], $match[1]);
$stmt->execute();
}
}
echo $free;
echo "<br>";
$i++;
}
我ID从您的查询中删除了列,因为我假设所有列都是自动生成的 ID,在这种情况下,您不需要为每个列都传递 NULL。
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报