我使用这个函数进行轮询,但我有一个不必要的步骤,我想以更实用的方式绕过它。然而,我不知道如何做到:
if(!$result = $db->query("SELECT * FROM mtp ORDER BY date DESC")){
die('There was an error running the query [' . $db->error . ']');
} else {
while($rows = mysqli_fetch_assoc($result)){
$records[] = $rows;
} //UNNECCESSARY STEP
for ($i = 0; $i < count($records); $i++) {
$records[$i][date] = strtotime($records[$i][date]) * 1000;
} //UNNECCESSARY STEP
}
print( json_encode($records));
您可以将循环组合为一个。
if(!$result = $db->query("SELECT * FROM mtp ORDER BY date DESC")){
die('There was an error running the query [' . $db->error . ']');
}
while($row = mysqli_fetch_assoc($result)){
$row["date"] = strtotime($row["date"]) * 1000;
$records[] = $row;
}
echo json_encode($records);
我不知道你为什么要把时间整数乘以一千
如果if语句包含exit((或die((,则不需要其他语句。