Forum Moderators: coopster
for example
SELECT * from blah order by recordID
if ($lastrecordID!="currentrecordID"){Do stuff}
This works fine until I get to the last record where because there are no more records it will not trigger the if statement.
Is there a way to find out what the next record will be so that if there isnt one I can print out the total?
OR is there a better way of doing this?
if ($lastrecordID!="currentrecordID" ¦¦!isset(currentrecordID)){
Do stuff
if (!isset(currentrecordID)) {
print totals;
}
}
there are a ton of methods for it, you could else if (!isset(currentrecordID)) or you could put a check in the bottom of the original if but that depends on other logic, to name a few.
bcolflesh - totals are in hour:minute format and wont add them up properly
jatar_k - I'm looping through results so it will never trigger the!isset part
//mysql stuff here
for ($i=0; $i < $num; $i++) {
$jobName=mysql_result($result,$i,"jobName");
$jobID=mysql_result($result,$i,"jobID");
$total=mysql_result($result,$i,"total");
if ($prevjobID!=$jobID){ print out totals }
id1 1:00
id1 4:00
id3 2:00 (id3!=id1 so it will spit out totals for id1)
1d3 1:15
the last ids will never get printed cos nothing to compare it against
ie last loop would look like - id3 DOES EQUAL id3 so nothing happens
-------------------------------------------------
Hmmmmm, just copied the [do stuff] bit and placed it after the closing loop brace so it will always print out totals - works fine now :)