my program gets data out of database and puts each row of values into an array so array[0] array[1] etc.
one values is called End_Date, which can only be ever between 2 years. i.e it could be only 2003, or it could be 2003 or 2004 or 2003 and 2002. not 2003 and 2001 etc. the table is also sorted by end_date which means it starts from teh higest year down
so it goes from 2004, 2004, 2003, 2003. or 2004, 2004 2004 etc.
the table can contain no values, values from only 1 year or 2 years. (the table is acctually a query).
What I need to do is know which array[which number] changes year if any. so i if I have
array[0] = 2004
array[1] = 2004
array [2] = 2003
array [3] = 2003
I want to know that array [2] is the array value which is the first 1 year which is lower then the arrays values before that.
However I am not good enough to writte the function for this. I have nerly done it but obviously it doesnt work. I think because the
if (array[1] < array[2])
doesnt work cause < can only cope with numbers. But I dont know how I geat each value out of a specific array key. 🙁
can somebody writte my function for me? or fix it.
here all my code. the function is called highestyear($years). I start my code from the while loop which extratcs all the table. {odbc by the way}
while($row = odbc_fetch_array($getdata)) { //the while loop to extract each successive row
$datestyle = "d.m.Y"; //datasystem used in DB is defined here
$counter++;
//gets the Year and month
$enddate = $row['End_Date'];
$datestyley = "Y"; //year xxxx style
$datestylen = "n"; //month from 1 to 12
$enddateyeardate = date($datestyley, strtotime($enddate)); //starts from highest to lowers i.e. 2004 to 2003
$enddateyear = (int) $enddateyeardate; //intreger
$enddatemonth[$counter] = date($datestylen, strtotime($enddate));
$year[$counter] = $enddateyear;
$Account_no[$counter] = $row['Account_No'];
$Invoice_no[$counter] = $row['Invoice_No'];
$Invoice_total[$counter] = number_format($row['Invoice_Total'],2);
$startdate[$counter] = date($datestyle, strtotime($row['Start_Date']));
$enddate[$counter] = date($datestyle, strtotime($row['End_Date']));
$Provider[$counter] = $row['Provider'];
$Total = $Total + $row['Invoice_Total']; //for calculating Total
}
function dump_array($array) {
echo "<table border=\"1\"><tr><td>Key</td><td>Value</td></tr>";
foreach($array as $key => $val){
echo "<tr><td>" . $key . "</td><td>";
if (is_array($val)) {
dump_array($val);
} else {
echo $val;
}
echo "</td></tr>";
}
echo "</table>";
}
$numberofresults = $counter;
function highestyear($years) {
$yearcounter = 0;
$yearcounter2 = 1;
$yearchangelower = 0;
while (count($years) != 0) {
if (isset($years[1])) { //if year exists and year variable is bigger then 1
while ($years[$yearcounter] < $years[$yearcounter2]) {
if ($years[$yearcounter] < $years[$yearcounter2]) {
$yearcounter++;
$yearcounter2++;
$yearchangelower++;
echo $years[$yearcounter];
}
else
return $yearchangelower;
}
}
$yearchangelower = 666;
return $yearchangelower;
}
}
/* while (list($key, $val) = each($year)) {
echo "Year[" . $key . "] = " . $val . "\n";
}
*/
//highestyear($year);
//$yearh = highestyear($year);
//echo $yearh;
list($key, $val) = $year[1];
echo $val;
}