Re: 2 errors I can not understand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It worked for you? It didn't for me until i changed

if ($s%$d=0)

to

if($s%$d == 0)

Jake


----- Original Message ----- From: "Jonathan Kahan" <jonathan@xxxxxxxxxxxxxx>
To: "Tijnema !" <tijnema@xxxxxxxxx>
Cc: "php Lists" <php-general@xxxxxxxxxxxxx>
Sent: Tuesday, March 13, 2007 6:08 PM
Subject: Re:  2 errors I can not understand


That worked in answering part 1 now i got to figure out part 2

----- Original Message ----- From: "Tijnema !" <tijnema@xxxxxxxxx>
To: "Jonathan Kahan" <jonathan@xxxxxxxxxxxxxx>
Cc: "php Lists" <php-general@xxxxxxxxxxxxx>
Sent: Tuesday, March 13, 2007 5:55 PM
Subject: Re:  2 errors I can not understand


On 3/13/07, Jonathan Kahan <jonathan@xxxxxxxxxxxxxx> wrote:
Hi all,

Please see my output  below followed by the code. I have been trying for
some to figure out why

1) I can not get a line feed to work in the web page that i am using to
display the output as I am not running from the commad line
Line feed in a browser is made with the HTML tag br
instead of printint "\r\n" you should try "<br>"

2) Why my loop is only executing 3 times when i want it to execute 50
I don't see any error in that loop, on my test server it is executing
50 times...

Any help would be greatly appreciated.

Jonathan

The next line is all that displays on the output html page:

Output: The number 0 is 0 The number 1 is 0 The number 2 is 1 The number 3
is 1

php script:

<html>
<body>
<?php
for ($k=0;$k<50;$k++)
{
echo ("The number ".$k." is ".isprime($k));
echo "\r\n";
}

function isprime ($s)
{
$a="2";

               switch ($s)
               {
               case "0":
               $a="0"; break;
               case "1":
               $a="0"; break;
               case "2":
               $a="1"; break;
               default:
               $d=3;
                       while ($d<$s)
                       {
                               if ($s%$d=0)
                               {
                               $a="0";
                               }
                       $d+=2;
                       }
               }

               if ($a=="2")
               {
               $a="1";
               }
return $a;
}
?>
</body>
</html>

"tjon2.php" 78L, 447C written

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





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


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux