Variable column name

I’ve worked with SQL before but this time I’m working with MySQL and with some custom PHP I’m trying to clean up for a friend and as such his tables are not adjustable for what is needed.

The table has a column for each day of the general week (Mo-Su) and they are an integer field for data manipulation. The code needs to select a value from one of those columns but which one won’t be known until runtime.


$query_Recordset1 = "SELECT id,advertiser,cartnumber,monday,tuesday,wednesday,thursday,friday,saturday,sunday,startdate,enddate,starttime,endtime,flight,tempspnsr FROM sheet WHERE $dayOfWeek > 0 AND startdate <= '$Date' AND enddate >= '$Date'";
$Recordset1 = mysql_query($query_Recordset1, $TestConn) or die(mysql_error());
	
while($row_Recordset1 = mysql_fetch_assoc($Recordset1))
{
          $numperday=$row_Recordset1["$dayOfWeek"]; //this line is what I want to do.
}

I was able to do this code with the

$numperday=mysql_result($Recordset1,$i,"$dayOfWeek");

but then I have to keep track of the i variable in my while loop, so I wanted to use mysql_fetch_assoc instead.