While looping

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>&nbsp;</td>
      <td valign="top" class="week"><?=$TotalPrReceieved ?></td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><?=$TotalPrShipped ?></td>
    <td>&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="week"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td>&nbsp;</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>&nbsp;</td>
    <td valign="top" class="na"><?=$InventoryPrReceieved ?> </td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na">N/A</td>
    <td>&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
  <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" class="na"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td>&nbsp;</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>&nbsp;</td>
      <td valign="top" ><?=$rs[6]?></td>
    <td valign="top" ><?=$rs[7]?></td>
    <td valign="top" ><?=$rs[8]?></td>
    <td>&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td valign="top" ><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td>&nbsp;</td>
    </tr>

    <? 
	$i++;
        $PreviousWeekday = $DayOfWeek; 
         }// While Ends ?>
</table></td>
[/code]

MOD EDIT: Added code tags

What do you mean ‘gives a record at the end’? What I can tell from the code is that only the values from the SQL query are in the table at all.

Yes you are right, I am trying to display values from the query.
Let me explain.
There are data which are entered onto a table each day. I am displaying a weekly report. At the end of each week there are few calculations from the daily entry and displayed. I am displaying it in two rows.
I have to now display the daily data right above the weekly figures, but when I do that, there is one row which is displayed after the weekly figures rows.
The rest are fine, except for that.
I hope I am making sense.

Do you have this live (or could you post the outputted HTML code)? I don’t think I get what the issue is.

Hi Zyphorra
Thank you so much.
I have done it some how, but still I am not happy with the code that I have written.
Moreover, now they want a change too.
Here is the link to the live page
http://www.turbocamindia.com/nozzle/p_LogNoz.php
Please help…
Regards
Eugene

Sponsor our Newsletter | Privacy Policy | Terms of Service