Re: Re: bcadd

From: Date: Fri, 18 Apr 2003 04:04:01 +0000
Subject: Re: Re: bcadd
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144375@lists.php.net to get a copy of this message
$TOTAL = preg_replace("/[()]+/"," ", $TOTAL); Kevin, I don't know if this generates a 'string' or a 'number.' If it generates a string, then you are adding a string to a number, and it might cause the bcadd function to fail. Hugh ----- Original Message ----- From: "Kevin Hoffer" <kevinh@inetplus.net> To: "'Hugh Danaher'" <hdanaher@earthlink.net> Sent: Thursday, April 17, 2003 8:45 PM Subject: RE: [PHP] Re: bcadd > I put the full code in the one message but I have pasted it below for > your review. This is strange and the 1st time I have ever seen it. I > have it setup now using just $TOTAL_HOURS = $HOURS + $TOTAL_HOURS but > that same thing doesn't work in the bcadd.. > > > <? > > $TOTAL_HOURS = "0"; > > $TOTAL_MIN = "0"; > > $LAST =`/usr/local/bin/radlast -10 arronpam | grep -v "radwtmp begins" | > tr > "\n" "~" | tr -s "~" | tr "~" "\n"`; > > $MINUS_SPACE = preg_replace("/[ ]+/"," ", $LAST); > > $lines = explode("\n",$MINUS_SPACE); > > print "<TABLE > BORDER=1><TR><TD>Username</TD><TD>Port</TD><TD>IP > > Address</TD><TD>Date</TD><TD>Start</TD><TD>End</TD><TD>Total</TD></TR>"; > > foreach ($lines as $line) { > > $ARRAY = split(" ",$line); > > if ($ARRAY[0] != "") { > > $USERNAME = $ARRAY[0]; > > $PORT = $ARRAY[1]; > > $IP = $ARRAY[2]; > > $DAY = $ARRAY[3]; > > $MONTH = $ARRAY[4]; > > $DATE = $ARRAY[5]; > > $START = $ARRAY[6]; > > $END = $ARRAY[8]; > > $TOTAL = $ARRAY[9]; > > $TOTAL = preg_replace("/[()]+/"," ", $TOTAL); > > $TOTAL_SPLIT = split(":",$TOTAL); > > $HOUR = $TOTAL_SPLIT[0]; > > $MIN = $TOTAL_SPLIT[1]; > > $TOTAL_HOURS = $TOTAL_HOURS + $HOUR; > > // $TOTAL_HOURS = bcadd($HOUR,$TOTAL_HOURS,0); > > // $TOTAL_MIN = bcadd($TOTAL_MIN,$MIN,0); > > $TOTAL_MIN = $MIN + $TOTAL_MIN; > > print > "<TR><TD>$USERNAME</TD><TD>$PORT</TD><TD>$IP</TD><TD>$DAY > $MONTH > > $DATE</TD><TD>$START</TD><TD>$END</TD><TD>$HOUR:$MIN</TD>"; > > } > > } > > $MIN_DIV = bcdiv($TOTAL_MIN,60); > > $YEAH = bcmul($MIN_DIV,60); > > $YEAH2 = bcsub($TOTAL_MIN,$YEAH); > > $TOTAL_HOURS=bcadd($MIN_DIV,$TOTAL_HOURS); > > $TOTAL_MIN = $YEAH2; > > print "<TR><TD COLSPAN=6 ALIGN=RIGHT>Total time</TD><TD ALIGN=RIGHT > COLSPAN=1>$TOTAL_HOURS:$TOTAL_MIN</TD></TR>"; > > print "</TABLE>"; > > ?> > > Kevin Hoffer > kevinh@chartermi.net > > > -----Original Message----- > From: Hugh Danaher [mailto:hdanaher@earthlink.net] > Sent: Thursday, April 17, 2003 11:47 PM > To: Kevin Hoffer > Cc: php-general@lists.php.net > Subject: Re: [PHP] Re: bcadd > > What does your loop look like? Basically, I'm interested in knowing > whether > you are somehow resetting or setting $TOTAL or $HOURS to zero before > going > to the bcadd() function. > Hugh > ----- Original Message ----- > From: "Kevin Hoffer" <kevinh@inetplus.net> > To: <php-general@lists.php.net> > Sent: Thursday, April 17, 2003 8:29 PM > Subject: [PHP] Re: bcadd > > > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 01 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 02 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > HOUR: 00 TOTAL_HOURS: 0 > > total hours: 0 > > > > "Jean-Christian Imbeault" <jc@mega-bucks.co.jp> wrote in message > > news:3E9F6B75.6010904@mega-bucks.co.jp... > > > Kevin Hoffer wrote: > > > > > > > > That one works. It displays 3. > > > > > > Hum ... > > > > > > > I thought maybe it had something to do with using two variables > but > that > > was > > > > squashed when I used two variables in another section of the > script. > > > > > > Can't quickly see what the problem could be. > > > > > > Try adding this in your code just for debugging and see if you can > spot > > > the problem: > > > > > > echo "HOUR: $HOUR TOTAL_HOURS: $TOTAL_HOURS<BR>"; //new > > > $TOTAL_HOURS = $TOTAL_HOURS + $HOUR; > > > echo "total hours: $TOTAL_HOURS<BR>"; //new > > > $TOTAL_HOURS = bcadd($HOUR,$TOTAL_HOURS,0); //new > > > echo "total hours: $TOTAL_HOURS<BR>"; //new > > > exit; //new > > > > > > Jean-Christian Imbeault > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > >

« previous php.general (#144375) next »