这个脚本工作正常,但我如何按日期创建搜索,如搜索2012/1/1至2012/12/31
这两个脚本都正常工作,但我想知道我怎么可以一起加入???因为我想创建一个图表,搜索日期之间的日期
这是图表脚本
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>";
?>
这是在2日期之间显示2行总和显示的第2个脚本,但是我不想要总和我只想要按照日期创建的图表
<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>
答案 0 :(得分:0)
您可以将sql查询从第二个脚本复制到第一个脚本吗?将between子句脚本添加到第一个子句时,它可以解决您的问题吗?