该代码片段旨在返回此表中每个回合的最小和最大ID 我只是想知道是否有一个不太笨拙的方式来做到这一点。PHP mysqli是最简单的方法吗?
$query = "SELECT round FROM $tablename";
$rounds = Array();
if ($result = $Login->mysqli->query($query)) {
while ($row = $result->fetch_array(MYSQL_ASSOC)) {
$rounds[] = $row['round'];
}
}
$rounds = array_unique($rounds);
$rounds = array_values($rounds);
$roundBound = Array();
foreach ($rounds as $roundNum) {
$query = "SELECT MIN(id), MAX(id) FROM $tablename WHERE round = $roundNum;";
$result = $Login->mysqli->query($query);
$row = $result->fetch_row();
$roundBound[] = $row[0];
$roundBound[] = $row[1];
}
hurr ...
改为,
$query = "SELECT MIN(id), MAX(id) FROM $tablename GROUP BY round";
if($result = $Login->mysqli->query($query)) {
while ($row = $result->fetch_row()) {
$roundBound[] = $row[0];
$roundBound[] = $row[1];
}
}
最糟糕的做法,我想我不需要array_values打电话,因为我通过一个foreach做... – Jamie
这是萨吉和马克之间的折腾。感谢你们俩。 – Jamie