該代碼片段旨在返回此表中每個回合的最小和最大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