i have been wrecking myself trying to figure out how to get the results to display the way i want in a table. I've spent about 20 hours messing around with the IF statements and cannot produce the results i want.
for each record resulting in the array, I want the hours for that record to populate only the column for the proper day num (calculated basd on the date value).
the other columns should read zero.
$sql = "SELECT * from Timesheets" ;
$result = mysql_query($sql)
while($line = mysql_fetch_array($result))
{
$Date = $line["Date"];
$Hours = $line["Hours"];
$Datestamp = strtotime($Date); // convert format to make date calculations
$Day = date("D", $Datestamp); // results as Sun - Sat
$DayNum = date("w", $Datestamp ) + 1; // results as 1-7
/* NEED HELP _ DONT KNOW PROPER CODE FOR CONDITIONAL IN WHILE LOOP
// convert this record's hours to Day1Hrs - Day7Hrs based on this record's date
// this should determine which column to print result for # of hours
// only one column should have the value for hours, the other day's values should be zero
$Day1Hrs ="0"; $Day2Hrs ="0"; $Day3Hrs ="0"; $Day4Hrs ="0"; $Day5Hrs ="0"; $Day6Hrs ="0"; $Day7Hrs ="0";
if ( $DayNum = "1") { $Day1Hrs = $Hours ; } else { $Day1Hrs = "0" ; }
if ( $DayNum = "2") { $Day2Hrs = $Hours ; } else { $Day2Hrs = "0" ; }
if ( $DayNum = "3") { $Day3Hrs = $Hours ; } else { $Day3Hrs = "0" ; }
if ( $DayNum = "4") { $Day4Hrs = $Hours ; } else { $Day4Hrs = "0" ; }
if ( $DayNum = "5") { $Day5Hrs = $Hours ; } else { $Day5Hrs = "0" ; }
if ( $DayNum = "6") { $Day6Hrs = $Hours ; } else { $Day6Hrs = "0" ; }
if ( $DayNum = "7") { $Day6Hrs = $Hours ; } else { $Day7Hrs = "0" ; }
}
*/
$tableinfo .= "<tr>
<td nowrap align=\"left\">($Day $DayNum) $Day1Hrs</td>
<td nowrap align=\"left\">$Day2Hrs</td>
<td nowrap align=\"left\">$Day3Hrs</td>
<td nowrap align=\"left\">$Day4Hrs</td>
<td nowrap align=\"left\">$Day5Hrs</td>
<td nowrap align=\"left\">$Day6Hrs</td>
<td nowrap align=\"left\">$Day7Hrs</td>
</tr>\n";
}
// code to print results in table format
[code=php]
so for example,
If daynum is 1 (sunday's date) and hours are 8, then the respective row in the table should read:
8 0 0 0 0 0 0