我正在尝试使用 for 循环通过 MySQL 查询选择增量值。我在下面包含了示例代码:
<?php
$day_1="sep_28";
$day_2="sep_29";
$day_3="sep_30";
$query = mysql_query("SELECT * FROM table WHERE id = '$id'");
while ($row = mysql_fetch_assoc($query))
{
for ($i = 1; $i <= 3; $i++)
{
$dayVar = "day_".$i;
//$dayVarCount = $dayVar."_count"; // Don't really need this anymore, so removed.
$dayVarCount = $row[$$dayVar];
echo "$$dayVar.': '.$dayVarCount<p>"; // Edited.
}
}
?>
我想我已经接近了,但是当我运行代码时,我的页面显示如下:
$day_1.': '.0
$day_2.': '.2
$day_3.': '.5
有什么额外的建议吗?感谢您的大力帮助!