On Mar 29, 2007, at 4:52 PM, Zoltán Németh wrote:
<snip>
(I assume you want this calculation within one given day) you could read all rows into an array like $timeinfo = array(); $sql = "SELECT minute, sequence FROM table WHERE day='$day'"; $result = mysql_query($result); while ($row = mysql_fetch_assoc($result)) { $timeinfo[$row['sequence'] = $row['minute']; } and then calculate and echo the difference between any element of the array: $diff0_1 = $timeinfo[1] - $timeinfo[0];
$timeinfo[$row['sequence'] = $row['minute']; <--- is the "[" between $timeinfo and $row a typo? or is there supposed to be a closing "]" somewhere?
When I add a closing "]" to it as such: $timeinfo[$row['sequence'] = $row['minute']]; I get this error when I try and open the page:[Fri Mar 30 13:55:36 2007] [error] PHP Notice: Undefined index: minute in /Volumes/RAIDer/webserver/Documents/tests/oatstest/ oatstime.php on line 15 [Fri Mar 30 13:55:36 2007] [error] PHP Notice: Undefined index: in /Volumes/RAIDer/webserver/Documents/tests/oatstest/oatstime.php on line 15 [Fri Mar 30 13:55:36 2007] [error] PHP Notice: Undefined offset: 1 in /Volumes/RAIDer/webserver/Documents/tests/oatstest/oatstime.php on line 18 [Fri Mar 30 13:55:36 2007] [error] PHP Notice: Undefined offset: 0 in /Volumes/RAIDer/webserver/Documents/tests/oatstest/oatstime.php on line 18
Line 15 is this line: $timeinfo[$row['sequence'] = $row['minute']]; and line 18 has: $diff0_1 = $timeinfo[1] - $timeinfo[0];What I am trying to do is subtract $timeinfo[1] from $timeinfo[0] and then display the difference.
When I echo $timeinfo it just says "array" so my thinking is that the errors are caused by the array not being populated properly based on the extra "[" or a missing "]". Am I at least on the right track?
-- Jason Pruim japruim@xxxxxxxxxx Production & Technology Manager MQC Specialist (2005 certified) 3251 132nd Ave Holland MI 49424 616.399.2355 www.raoset.com"We hold these truths to be self-evident. That all men are created equal, that they are endowed by their creator with certain unalienable rights, (and) that among these are Life, Liberty, and the pursuit of Happiness."
Attachment:
smime.p7s
Description: S/MIME cryptographic signature