Hi I have written this code and I am stuck, running this code gives me a record at the end of the table, which is supposed to be above it . Please help
[code]
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<?
$SQL = "SELECT * FROM dailysales";
$result = mysql_query($SQL);
$RecordCount = mysql_num_rows($result);
$i = 1;
$WeekNumber = 1;
$WeekStarted = false;
$PreviousWeekday = 0;
?>
<?
// $InventoryPrReceieved = 0;
// $InventoryQSTReceieved = 0;
// $InventoryCoatedRingsCHS= 0;
while ($rs = mysql_fetch_array($result))
{
$datetime = $rs[0];
$year = substr($datetime,0,4);
$mon = substr($datetime,5,2);
$day = substr($datetime,8,2);
$timestamp = mktime(0, 0, 0, $mon, $day, $year);
$DayOfWeek = date('w',$timestamp);
if (
$PreviousWeekday > $DayOfWeek ||
$RecordCount == $i
)
{
$InventoryReceived = $TotalInventory + $InventoryReceived - $TotalTurned;
$InventoryTurned = $InventoryTurned + $TotalTurned - $TotalMilled;
$InventoryMilled = $InventoryMilled + $TotalMilled - $TotalShipped;
$InventoryPrReceieved = $TotalPrReceieved + $InventoryPrReceieved - $TotalPrShipped;
$InventoryQSTReceieved = $TotalQSTReceieved + $InventoryQSTReceieved - $TotalQSTShipped;
// $InventoryCoatedRingsCHS =
?>
<tr>
<td height="34" valign="top" class="weeknumber">Week
<?=$WeekNumber ?>
throughput</td>
<td valign="top" class="week"> <?=$TotalInventory ?> </td>
<td valign="top" class="week"><?=$TotalTurned ?></td>
<td valign="top" class="week"> <?=$TotalMilled ?> </td>
<td valign="top" class="week"> <?=$TotalShipped ?> </td>
<td> </td>
<td valign="top" class="week"><?=$TotalPrReceieved ?></td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><?=$TotalPrShipped ?></td>
<td> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="week"><!--DWLayoutEmptyCell--> </td>
<td> </td>
</tr>
<tr>
<td height="30" valign="top" class="inventory">Remaining Stock</td>
<td valign="top" class="na"><?=$InventoryReceived ?></td>
<td valign="top" class="na"><?=$InventoryTurned ?></td>
<td valign="top" class="na"><?=$InventoryMilled ?></td>
<td valign="top" class="na">N/A</td>
<td> </td>
<td valign="top" class="na"><?=$InventoryPrReceieved ?> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na">N/A</td>
<td> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td valign="top" class="na"><!--DWLayoutEmptyCell--> </td>
<td> </td>
</tr>
<?
$WeekNumber ++;
$TotalTurned = 0;
$TotalMilled = 0;
$TotalShipped = 0;
$TotalInventory = 0;
$TotalPrReceieved = 0;
$TotalPrShipped = 0;
$TotalQSTReceieved = 0;
$TotalQSTShipped = 0;
}
$TotalTurned += $rs[2];
$TotalMilled += $rs[3];
// $TotalShippedAir= $rs[5];
// $TotalShippedBoat= $rs[6];
$TotalShipped += $rs[4] ;
$TotalInventory += $rs[1];
$TotalPrReceieved += $rs[6];
$TotalPrShipped += $rs[8];
// $TotalQSTReceieved += $rs[7];
// $TotalQSTShipped += $rs[8];
// $TotalCoatedRingsCHS += $rs[9];
?>
<tr>
<td height="34" valign="top" >
<?=$rs[0] ?> </td>
<td valign="top" > <?=$rs[5] ?> </td>
<td valign="top" ><?=$rs[1]?></td>
<td valign="top" > <?=$rs[2]?> </td>
<td valign="top" ><?=$rs[3]?></td>
<td> </td>
<td valign="top" ><?=$rs[6]?></td>
<td valign="top" ><?=$rs[7]?></td>
<td valign="top" ><?=$rs[8]?></td>
<td> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td valign="top" ><!--DWLayoutEmptyCell--> </td>
<td> </td>
</tr>
<?
$i++;
$PreviousWeekday = $DayOfWeek;
}// While Ends ?>
</table></td>
[/code]
MOD EDIT: Added code tags