Ik heb een tabel aangemaakt via phpmyadmin met daarin een veld voor de datum opgeslagen als volgend formaat: "yyyy-mm-dd" + een veld voor een getal in te vullen.
Dat maakt dus een veld "datum" en een veld "stand".

Nu heb ik een scriptje voor statistieken te maken.
Alleen weet ik niet goed hoe het aan te passen aan dit datumformaat.
Dit is het script:

-------------------------------
<?php

//start the PHP multi-dimensional array and create the region titles
$chart [ 'chart_data' ][ 0 ][ 0 ] = "";
$chart [ 'chart_data' ][ 1 ][ 0 ] = "water";
$chart [ 'chart_data' ][ 2 ][ 0 ] = "elektriciteit";
$chart [ 'chart_data' ][ 3 ][ 0 ] = "gas";

//connect to the database
mysql_connect ( "localhost", "xxx", "" );
mysql_select_db ( "lastone" );

//get the smallest year to determine which year to start the chart with
$result = mysql_query ( "SELECT MIN(year) AS MinYear FROM Growth" );

$MinYear = mysql_result ( $result, 0, "MinYear" );

//get all the data in the Growth table
$result = mysql_query ("SELECT * FROM water1 ");


//extract the data from the query result one row at a time
for ( $i=0; $i < mysql_nu_rows($result1); $i++ ) {

//determine which row in the PHP array the current data belongs to
switch ( mysql_result ( $result, $i, "Region" ) ) {
case "water":
$row = 1;
break;

case "elektriciteit":
$row = 2;
break;

case "gas":
$row = 3;
break;
}

//determine which column in the PHP array the current data belongs to
$col = mysql_result ( $result, $i, "datum") - $MinYear + 1;

//populate the PHP array with the Year title
$chart [ 'chart_data' ][ 0 ][ $col ] = mysql_result ( $result, $i, "datum");

//populate the PHP array with the revenue data
$chart [ 'chart_data' ][ $row ][ $col ] = mysql_result ( $result, $i, "stand");
}

?>
<?php
include "charts.php";

//change the chart to a bar chart
$chart [ 'chart_type' ] = "bar";

SendChartData ( $chart );
?>

--------------------------------------


//get the smallest year to determine which year to start the chart with
$result = mysql_query ( "SELECT MIN(year) AS MinYear FROM Growth" );

$MinYear = mysql_result ( $result, 0, "MinYear" );


Dit stukje zou dus aangepast moeten worden aan mijn datumformaat , en niet alleen jaar.
Je hebt de datum als: yyyy-mm-dd.. dit kun je omzetten naar:

<?
$datum = "2006-05-01";
$datum_array = explode("-", $datum);
$nieuwe_datum = $datum_array[0] . $datum_array[1] . $datum_array[2];

// output: 20060501
echo $nieuwe_datum;
?>

Als je dat hebt kun je makkelijk sorteren.. Weet niet precies wat je verder wilt..
Bassie waarom niet
<?php
$datum = str_replace('-','',$datum);
echo $datum;
?>

On nog beter via date...
Je kunt ook gebruik maken van de datumfuncties in je query.
Scheelt ook weer al dat geƫxplode enzo ;)

Reageren