1

this script working fine but how can i create search by date like i m searching 2012/1/1 to 2012/12/31

these are two scripts both works properly but i want to know that how i can join both together???because i want to create a chart which search date between to date

and this is chart script

include 'create.php';
$sql="SELECT due_date,total FROM $tablename"; // Give Your field Name  +
$result = mysql_query($sql);
$graphtitle='BarChart';//Graph Title
$xname='Chart For The Year Of 2012 '; //X-axis Name
$yname='Sale Chart';//y-axis name
$img_width=600;//image height
$img_height=300;//image width 
$margins=70;
$ymargin=6;
$count=mysql_affected_rows();
$graph_width=$img_width - $margins * 2;
$graph_height=$img_height - $margins * 2; 
$bar_width=25;
$total_bars=$count;
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
$img=imagecreate($img_width,$img_height);
include 'barcolor.php';
imagefilledrectangle($img,0,0,0,0,$bag_color);
imageline($img,$margins,$img_height-45,$img_width-20,$img_height-45,$xyline_color);
imageline($img,$margins,$ymargin,$margins,$img_height-45,$xyline_color);
$maxvalue="select max(total) as total from $tablename";//Give your field name for Y axis 

$max=mysql_query($maxvalue);
while($inf1= mysql_fetch_array($max)) 
  {
   $ratio=$graph_height/$inf1[0];
  }
$horizontal_lines=8;
$horizontal_gap=($img_height+20)/$horizontal_lines;
for($j=1;$j<=$horizontal_lines;$j++)
{
        $y=($img_height-48) - $horizontal_gap * $j ;
        //imageline($img,$margins+1,$y,$img_width-20,$y,$hline_color);
        $v=intval($horizontal_gap * $j /$ratio);
        imagestring($img,2,$margins-30,$y-5,$v,$values_color);
}
$i=0;
while($inf = mysql_fetch_array($result)) 
  {
      $x1=($margins+10) + ($gap+5) + $i * ($gap+$bar_width) ;
      $x2=$x1+$bar_width;
      $y1=($img_height-46)- ceil($inf[1] * $ratio) ; 
      $y2=($img_height-46); 
      imagestring($img,2,$x1+1,$y1-15,$inf[1],$values_color); 
      imagestring($img,2,$x2-23,$img_height-43,$inf[0],$values_color);  
      imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color); // Draw bar
   $i++;   
  }
imagestring($img,8, ($img_width-$margin)/2, 0, $graphtitle, $txt_color);
imagestring($img,5, ($img_width-$margin)/2, $img_height-($ymargin+10), $xname, $txt_color);
imagestringup($img,5,10,($img_height-$ymargin)/2, $yname, $txt_color);
//header('Content-type: image/png');
imagepng($img, 'barchart.jpg');
echo "<div style='border:1px solid #d8d8d8;width:$img_width'><img src='barchart.jpg'></div>";
?>

and this is 2nd script which show 2 row sum show by between 2 date but i dont want a sum i want only chart which create by betwen to date

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal2.js"></script> 
</head>

<body>
<form action="index2.php" method="post">
From: <input name="from" type="text" class="tcal"/>
To: <input name="to" type="text" class="tcal"/>
<input name="" type="submit" value="Seach" />
</form><br />
Total Sales:  
<?php
$con = mysql_connect("localhost","db_search","password12");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db_search", $con);
function formatMoney($number, $fractional=false) {
    if ($fractional) {
        $number = sprintf('%.2f', $number);
    }
    while (true) {
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
        if ($replaced != $number) {
            $number = $replaced;
        } else {
            break;
        }
    }
    return $number;
}       
$a=$_POST['from'];
$b=$_POST['to'];
$result1 = mysql_query("SELECT sum(salary) FROM accounts where date BETWEEN '$a' AND '$b'");
    while($row = mysql_fetch_array($result1))
    {
        $rrr=$row['sum(salary)'];
        echo formatMoney($rrr, true);
    }
mysql_close($con);
?>

</body>
4

1 回答 1

0

Can you copy the sql query from the 2nd script to your first script? When you add the between clause script to the first clause it solves your problem?

于 2012-11-10T14:32:08.367 回答