I am trying to use a for loop to select an incremental value with a MySQL query. I have included sample code below:
<?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.
}
}
?>
I think I am getting close, but when I run the code my page is showing this:
$day_1.': '.0
$day_2.': '.2
$day_3.': '.5
Any additional recommendations? Thanks for the great help!