Re: math compoundingwrong results.

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: math compoundingwrong results.
Groups: php.general 
Request: Send a blank email to php-general+get-155@lists.php.net to get a copy of this message
I tested the date() and the getdate() functions with the following code snippets, and it worked fine. Remember that these functions have a second's resolution, so the value won't hardly change during the execution of one loop. That's why I inserted the sleep(1) statement (for testing purpose only;-)). ***************** <?php $i=0; while ($i<10) { $date=getdate(); echo $date['seconds']."<br>"; sleep(1); $i++; } ?> ***************** <?php $i=0; while ($i<10) { echo date("Y-m-d H:i:s")."<br>"; sleep(1); $i++; } ?> ***************** >Hello >I am having a math problem with hte following. >The date(), only happens during the first loop >and the result keeps compounding. How can I force >it to happen everytime? I tired an Unset() o nhte >$date, it didnt work. Ideas? > >Eric > >while($row = mysql_fetch_array($result)) >{ >$query1 = "SELECT * FROM members WHERE username >= '$row[username]' "; >$result1 = mysql_query($query1); >$row1 = mysql_fetch_array($result1); > >$query2 = "SELECT * FROM pictures WHERE username >= '$row[username]' "; >$result2 = mysql_query($query2); >$row2 = mysql_fetch_array($result2); > >print "<tr>"; >print "<td width=18%>"; >print "<a href=*.php3?susername="; >print "$row[username]"; >print ">"; >echo $row[username]; >print "</a></td>"; >print "<td width=9%>"; >echo $row1[memmdl]; >print "</td>"; >print "<td width=25%>"; >echo $row1[memyr]; >print "</td>"; >print "<td width=24%>"; > if (empty($row2[picture_name])) > { > print "no picture <img >src=http://www.ultimatenetwork.net/nphoto.gif>";} > else{print "yes picture <img >src=http://www.ultimatenetwork.net/photo.gif>";} >print "</td>"; >print "<td width=24%>"; >$query3 = "SELECT * FROM whos WHERE username = >'$row[username]' "; >$result3 = mysql_query($query3); >$row3 = mysql_fetch_array($result3); >$hour2 = (int)substr($row3[entry], 8, 2); >$minute2 = substr($row3[entry], 10, 2); >if ( $minute2 < 10) { > $minute2= "0$minute2"; >} >$date = getdate(); >$minutes = $date[ 'minutes']; >$hours = $date[ 'hours']; >if ( $minutes < 10) { > $minutes= "0$minutes"; >} >if ($mintues < $minute2) >{ >$nhours = $hours -1; >$nminutes = $mintues +60; >$rhour = $nhours - $hour2; >$rmin = $nminutes - $minute2; >}else{ >$rhour = $hours - $hour2; >$rmin = $minutes - $minute2; >} >if ($rhour < 1) >{ print $rmin; >print " mintues"; } >else >{ >print $rhour; >print " hours "; >print $rmin; >print " minutes"; >} >print "</td>"; >print "</tr>"; >} >print "</table>"; > > >__________________________________________________ >Do You Yahoo!? >Send instant messages & get email alerts with Yahoo! Messenger. >http://im.yahoo.com/ > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#155) next »