 |
Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Comunitatea PHP Romania
|
| Subiectul anterior :: Subiectul următor |
| Autor |
Mesaj |
crack
Data înscrierii: 28/Ian/2005
Mesaje: 7
Locație: Iasi
|
| Trimis: Mar Feb 01, 2005 6:20 pm Titlul subiectului: diferenta intre 2 date |
|
|
urmatorul cod face un grafic pentru 2(data si valoare) inregistrari din o baza de date.
problema vine in a pune un grid care sa funcioneze..
aici fol $pas_val care e un nr care se schimba in fct de cat de mult inreg sunt...
dar cum fac sa se schimbe distanta intre 2 pct pe grafic in fct de distanta in zile intre $vect[1]['data'] - $vect[0]['data'] ?
Cod:
$camp_data=$HTTP_GET_VARS['data'];
$camp_val=$HTTP_GET_VARS['val'];
$camp_tabela=$HTTP_GET_VARS['tabela'];
$camp_tip=$HTTP_GET_VARS['tip'];
mysql_connect("localhost","use","pass") or
die("Nu ma pot conecta la baza de date");
mysql_select_db("$camp_tabela") or
die ("Nu am putut selecta baza de date");
$query = "SELECT $camp_data,$camp_val FROM $camp_tabela order by $camp_data";
$rs = @mysql_query($query);
$i=0;
$data=array();
while($row=mysql_fetch_array($rs)){
//$data[$i]=$row['data'];
//$valoare[$i]=$row['valoare'];
$vect[$i] = $row;
$i++;
}
$maxx=mysql_query("SELECT MAX($camp_val) FROM $camp_tabela");
$minn=mysql_query("SELECT MIN($camp_val) FROM $camp_tabela");
$val_max=number_format(mysql_result($maxx, 0,0),3);
$val_min=number_format(mysql_result($minn, 0,0),3);
if ($camp_tip==1)
{
$nr=(count($vect)-1);
$max_dim = 300;
if ($val_max>=max_dim)
{
}
$pas_val = 300/$nr;
header("Content-type: image/png");
$im = @imagecreate(400, 400)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 203, 233, 51);
$line_color = imagecolorallocate($im, 0, 0, 0);
$point_color = imagecolorallocate($im, 255, 0, 0);
imagestring($im, 10, 60, 20, "Grafic valori", $text_color);
$x1 = 40;
$y1 = $max_dim-$vect[0]['valoare'];
$points[0] = 40+1;
$points[1] = $max_dim-1;
$points[2] = $x1+1;
$points[3] = $y1+1;
imageline($im, 40, 0, 40, $max_dim, $line_color);
imageline($im, 40, $max_dim, 400, $max_dim, $line_color);
imagestring($im, 1, 10, 310, $vect[0]['data'], $line_color);
imagestring($im, 1, 0, 280, $val_min, $line_color);
for($i=1; $i<count($vect); $i++) {
$x2 = $x1+$pas_val;
$y2 = $max_dim - $vect[$i]['valoare'];
$points[2*($i+1)] = $x2;
$points[2*($i+1)+1] = $y2+1;
imageline($im, $x1, $y1, $x2, $y2, $line_color);
$x1 = $x2;
$y1 = $y2;
}
imagestring($im, 1, 330,310, $vect[$nr]['data'], $line_color);
imagestring($im, 1, 0,210, $val_max, $line_color);
$points[2*($i+1)] = $x2+1;
$points[2*($i+1)+1] = $max_dim-1;
imagefilledpolygon($im, $points, count($points)/2, $text_color);
$x1 = 40;
$y1 = $max_dim-$vect[0]['valoare'];
$points[0] = 40+1;
$points[1] = $max_dim-1;
$points[2] = $x1+1;
$points[3] = $y1+1;
for($i=1; $i<=count($vect); $i++) {
$x2 = $x1+$pas_val;
$y2 = $max_dim - $vect[$i]['valoare'];
$points[2*($i+1)] = $x2;
$points[2*($i+1)+1] = $y2+1;
imagefilledrectangle($im,$x1-2,$y1-2,$x1+2,$y1+2,$point_color);
$x1 = $x2;
$y1 = $y2;
}
imagepng($im);
imagedestroy($im);
}
else............... |
|
| Sus |
|
johnny
Data înscrierii: 31/Iul/2004
Mesaje: 904
Locație: Bucuresti
|
| Trimis: Mar Feb 01, 2005 9:48 pm Titlul subiectului: |
|
|
an style="color: #000000"><?php $date_pieces=explode('-',$DATA1);
$time_data1 = mktime(0,0,0,$date_pieces[1],$date_pieces[2],$date_pieces[0]);
$date_pieces=explode('-',$DATA2);
$time_data2 = mktime(0,0,0,$date_pieces[1],$date_pieces[2],$date_pieces[0]);
#diferenta dintre cele 2 date in secunde
$diffDateSec = $time_data2-$time_data1;
// acum 1 ora = 3600 sec, 1 zi = 24*3600
$diffDateDays = $diffDateSec/(24*3600);
Recomand consultarea manualului php: mktime(), date() |
|
| Sus |
|
crack
Data înscrierii: 28/Ian/2005
Mesaje: 7
Locație: Iasi
|
| Trimis: Mie Feb 02, 2005 2:00 pm Titlul subiectului: |
|
|
exact
Cod: function DateDiff ($date1,$date2) {
$arr1 = explode("-",$date1);
$d1 = mktime( 0,0,0,$arr1[1],$arr1[2],$arr1[0]);
$arr2 = explode("-",$date2);
$d2 = mktime( 0,0,0,$arr2[1],$arr2[2],$arr2[0]);
$timedifference = $d2 - $d1;
$retval = bcdiv($timedifference,86400);
return $retval;
} |
|
| Sus |
|
PHPRomania Bot
Bot Member
Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google |
| Trimis: Mie Dec 26, 2007 7:01 pm Titlul subiectului: Ad |
|
|
|
|
|
| Sus |
|
| |
|