Math Operator Problem?

Math Operator Problem?

am 09.02.2009 13:32:00 von Alice Wei

--_96a719e8-d1df-4686-89d5-7da78ff88d55_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Hi,

I have a snippet of code as follows:

while (!feof($fh2)) {
=20
$total_time=3D0=3B
$lines=3D fgets($fh2)=3B
$count=3D strlen($lines)=3B
if ($count == 0) {
//There are no lines
}
else {

$total_time +=3D $lines=3B
=20
}
}

What I am trying to do here is to increment the total_time value and have i=
t display on the screen without changing the actual input file. However=2C =
when I tried to output the result on the screen=2C all I am getting is the =
same value as I have in the text file originally. Can anyone on the list pl=
ease give me some insight on what I am doing wrong here?=20
Thanks in advance.


Alice


____________________________________________________________ _____
All-in-one security and maintenance for your PC.=A0 Get a free 90-day trial=
!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=3Dw l_wlmail=

--_96a719e8-d1df-4686-89d5-7da78ff88d55_--

Re: Math Operator Problem?

am 09.02.2009 16:34:45 von James Crow

On Mon, 2009-02-09 at 07:32 -0500, Alice Wei wrote:
> Hi,
>
> I have a snippet of code as follows:
>
> while (!feof($fh2)) {
>
> $total_time=0;
> $lines= fgets($fh2);
> $count= strlen($lines);
> if ($count == 0) {
> //There are no lines
> }
> else {
>
> $total_time += $lines;
>
> }
> }
>
> What I am trying to do here is to increment the total_time value and
> have it display on the screen without changing the actual input file.
> However, when I tried to output the result on the screen, all I am
> getting is the same value as I have in the text file originally. Can
> anyone on the list please give me some insight on what I am doing
> wrong here?
> Thanks in advance.
>
>
> Alice
>

Alice,

It might help if you posted a couple of lines from the $fh2 file. Are
any of the lines in it empty?

Thanks,
James



--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

FW: Math Operator Problem?

am 09.02.2009 17:26:30 von Alice Wei

--_b049278e-9b1b-472f-a8f0-9053b1af8ae4_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable




> From: james@ultratans.com
> To: ajwei@alumni.iu.edu
> CC: php-windows@lists.php.net
> Date: Mon=2C 9 Feb 2009 10:34:45 -0500
> Subject: Re: [PHP-WIN] Math Operator Problem?
>=20
> On Mon=2C 2009-02-09 at 07:32 -0500=2C Alice Wei wrote:
> > Hi,
> >=20
> > I have a snippet of code as follows:
> >=20
> > while (!feof($fh2)) {
> >=20
> > $total_time=3D0=3B
> > $lines=3D fgets($fh2)=3B
> > $count=3D strlen($lines)=3B
> > if ($count == 0) {
> > //There are no lines
> > }
> > else {
> >=20
> > $total_time +=3D $lines=3B
> >=20
> > }
> > }
> >=20
> > What I am trying to do here is to increment the total_time value and
> > have it display on the screen without changing the actual input file.
> > However=2C when I tried to output the result on the screen=2C all I am
> > getting is the same value as I have in the text file originally. Can
> > anyone on the list please give me some insight on what I am doing
> > wrong here?=20
> > Thanks in advance.
> >=20
> >=20
> > Alice
> >=20
>=20
> Alice=2C
>=20
> It might help if you posted a couple of lines from the $fh2 file. Are
> any of the lines in it empty?=20
>=20
=20
Hi=2C James:=20
=20
I believe this is something like what is in my file:
=20
3
4
2
=20
Note that there is an extra line break after the last line=2C but I am not =
sure if that was what caused the problem. My code above intentionally made =
the calculation leave out the last line. Or=2C is it not what it was doing?
=20
Thanks again.

> Thanks=2C
> James
>=20
>=20
>=20
> --=20
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe=2C visit: http://www.php.net/unsub.php
>=20




Use Messenger to talk to your IM friends=2C even those on Yahoo! Talk now!
____________________________________________________________ _____
Use Messenger to talk to your IM friends=2C even those on Yahoo!
http://ideas.live.com/programpage.aspx?versionId=3D7adb59de- a857-45ba-81cc-=
685ee3e858fe=

--_b049278e-9b1b-472f-a8f0-9053b1af8ae4_--

Re: FW: Math Operator Problem?

am 09.02.2009 17:58:58 von James Crow

On Mon, 2009-02-09 at 11:26 -0500, Alice Wei wrote:

> > > while (!feof($fh2)) {
> > >
> > > $total_time=0;
> > > $lines= fgets($fh2);
> > > $count= strlen($lines);
> > > if ($count == 0) {
> > > //There are no lines
> > > }
> > > else {
> > >
> > > $total_time += $lines;
> > >
> > > }
> > > }

> 3
> 4
> 2
>
> Note that there is an extra line break after the last line, but I am not sure if that was what caused the problem. My code above intentionally made the calculation leave out the last line. Or, is it not what it was doing?
>

Alice,

I reread your post and think I understand now what you are trying to
do. Every time the while() loop runs (for each line in $fh2) the
$total_time variable gets set to '0'. When the if/else loop runs 0 gets
added to $lines and the result will always be the value of $lines.

If you want the $total_time to increment with each line in the $fh2
file then you need to declare it outside the while() loop instead of
inside the loop.

Cheers,
James



--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php