我在使用 php 编码时遇到了一些问题。我想要做的是:
- 创建一个数组 ($rows) 并用 mysqli_query ($query1) 的结果填充它 --> OK
- 对于该数组中的每个元素,将某个键的值 (pilot_rule_id) 替换为另一个 mysqli_query ($query2) 的结果。(第二个查询将返回一行,因为 Pilot 表的 id 是主键)。
到目前为止我有
$id = "96707ac6-ecae-11ea-878d-005056bbb446";
$rows = array();
$query1 = mysqli_query($con, "SELECT * FROM pilot_time_schedule WHERE pilot_id='$id'");
while($r = mysqli_fetch_assoc($query1)) {
$rows[] = $r;
}
foreach($rows as $pilotRuleId) {
$pilotRuleId->$pilot_rule_id;
$query2 = mysqli_query($con, "SELECT name FROM pilot_rule WHERE id='$piloteRuleId'");
while($r = mysqli_fetch_assoc($query2)) {
$result[] = $r;
}
// Don't know how to continue from here