<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style2 {font-size: 12px}
.style4 {font-size: 12px; font-weight: bold; }
-->
</style>
</head>
<body>
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#990000">
  <tr>
    <td bgcolor="#FFFF99">&nbsp;</td>
    <td bgcolor="#FFFFFF">จันทร์&nbsp;&nbsp;&nbsp;</td>
    <td bgcolor="#FFD2FF">&nbsp;</td>
    <td bgcolor="#FFFFFF">อังคาร&nbsp;&nbsp;&nbsp;</td>
    <td bgcolor="#A8FFA8">&nbsp;</td>
    <td bgcolor="#FFFFFF">พุธ&nbsp;&nbsp;&nbsp;</td>
    <td bgcolor="#FFD280">&nbsp;</td>
    <td bgcolor="#FFFFFF">พฤหัสบดี&nbsp;&nbsp;&nbsp;</td>
    <td bgcolor="#8CFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">ศุกร์&nbsp;&nbsp;&nbsp;</td>
    <td bgcolor="#E3CFF1">&nbsp;</td>
    <td bgcolor="#FFFFFF">เสาร์&nbsp;&nbsp;&nbsp;</td>
  </tr>
</table>
<br />
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#990000">
  <tr>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">วันที่</span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">เวลา</span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทองคำแท่ง <br />
      96.5%<br />
    รับซื้อบาทละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทองคำแท่ง <br />
      96.5%<br />
    ขายบาทละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทองรูปพรรณ <br />
      96.5%<br />
    รับซื้อกรัมละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทองรูปพรรณ <br />
      96.5%<br />
    รับซื้อบาทละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทองรูปพรรณ <br />
      96.5%<br />
    ขายบาทละ</span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทอง 90%<br />
รับซื้อกรัมละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทอง 90%<br />
ซื้อบาทละ</span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทอง 40%<br />
รับซื้อกรัมละ </span></td>
    <td align="center" valign="top" bgcolor="#FFCC00"><span class="style4">ทอง 40%<br />
    ซื้อบาทละ</span></td>
    <td align="center" valign="top" bgcolor="#FFCC00" class="style4">&nbsp;</td>
  </tr>
<?

$user="cp037684_tbadm";
$password="siamnovaTho1220!";
$database="cp037684_tbadm";

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");



$day1=strip_tags($_GET['orderdate1']);	
$day2=strip_tags($_GET['orderdate2']);	

$b1=strtotime($day1);
$b2=strtotime($day2);

if($b1<$b2)     {   
                                 $d1=$day1; 
                                 $d2=$day2; 
	        							}else{									
						                                 $d1=$day2; 
						                                 $d2=$day1; 
														}
														
$query="SELECT * FROM goldprice   WHERE   date BETWEEN DATE_FORMAT('$d1' ,'%Y-%m-%d') AND DATE_FORMAT('$d2','%Y-%m-%d') ORDER BY date  DESC, time DESC"; //
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$date2 =$date;

$id=mysql_result($result,$i,"id");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$b96sb=mysql_result($result,$i,"b96sb");
$b96bb =mysql_result($result,$i,"b96bb");
$o96bg =mysql_result($result,$i,"o96bg");
$o96sb=mysql_result($result,$i,"o96sb");
$o96bb=mysql_result($result,$i,"o96bb");
$g90bg=$o96bg*.9;
$g90sb=$g90bg*15.16;
$g40bg=round($o96bg*.35);
$g40sb=$g40bg*15.16;

$dateshow=date("d/M/Y",strtotime($date));
$dd=date("w",strtotime($date));

if ($i<($num-1)){
                  $p_old =mysql_result($result,($i+1),"b96bb");
				  $diff=$b96bb-$p_old ;
			      $err=0;
            } else{
			                 $err=1;
			             }
switch ($dd)
{
case 0 :
$fc="#FFCACA";
break;  
case 1:
$fc="#FFFF99";
break;
case 2:
$fc="#FFD2FF";
break;
case 3:
$fc="#A8FFA8";
break;
case 4:
$fc="#FFD280";
break;
case 5:
$fc="#8CFFFF";
break;
case 6:
$fc="#E3CFF1";
break;
default:
$fc="#FFFFFF";
}

?>
  <tr>
    <td bgcolor="<?php echo $fc ?>" class="style2"><?php if($date2!=$date)echo $dateshow?></td>
    <td bgcolor="<?php echo $fc ?>" class="style2"><?php echo $time ?> </td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><strong><?php echo $b96bb ?></strong></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><strong><?php echo $b96sb ?></strong></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><strong><?php echo $o96bg ?></strong></td>
    <td align="center" bgcolor="<?php echo $fc ?>"class="style2"><?php echo $o96bb ?></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><?php echo $o96sb ?></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><?php echo $g90bg ?></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><?php echo $g90sb ?></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><?php echo $g40bg ?></td>
    <td align="center" bgcolor="<?php echo $fc ?>" class="style2"><?php echo $g40sb ?></td>
    <td align="left" bgcolor="<?php echo $fc ?>" class="style2">
	  <strong>
	  <?php
	   if($err==1)
	       {
		   			echo "";
		   }elseif($diff==0)
	       {
		   			echo "<img src=\"e.gif\" width=\"20\" height=\"20\" /> ($diff)";
		   }elseif($diff>0)
			       {
	 	   			     echo "<img src=\"u.gif\" width=\"20\" height=\"20\" /> ($diff)";
				   }elseif($diff<0)
				   		{
	 	   			          echo "<img src=\"d.gif\" width=\"20\" height=\"20\" /> ($diff)";
						}
		
	?>
    </strong></td>
  </tr>

<?

//echo "<b>| $date | $time | $b96sb | $b96bb | $o96sg | $o96sb | $o96bb</b><br>";

$i++;
}
$i=0;
$id=mysql_result($result,$i,"id");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$b96sb=mysql_result($result,$i,"b96sb");
$b96bb =mysql_result($result,$i,"b96bb");
$o96bg =mysql_result($result,$i,"o96bg");
$o96sb=mysql_result($result,$i,"o96sb");
$o96bb=mysql_result($result,$i,"o96bb");

?>
</table>
<p><br />
</p>
</body>
</html>