Jump to content

Archived

This topic is now archived and is closed to further replies.

KDragon

Page won't load??

Recommended Posts

Well, I wrote this php page and when i try to load it just sits there saying that it's transferring data from localhost (the server is on my comp). I'm pretty sure the following code is trying to do what I want it to do, which is change the text color from white to black (incremently, which is why I put it in a loop). I would just like to know why it doesn't load and just keeps transfering data.

[code]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
function colorDec($colorNum){
  $colorNum--;
  return $colorNum;
}
?>
<?php $colorNum=255; ?>
<p style="color: rgb(<?php while($colorNum > 0){echo colorDec($colorNum);} $colorNum=255; ?>,<?php while($colorNum > 0){echo colorDec($colorNum);} $colorNum=255; ?>,<?php while($colorNum > 0){echo colorDec($colorNum);} ?>)">This be some text.</p>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=367834:date=Apr 24 2006, 11:55 AM:name=KDragon)--][div class=\'quotetop\']QUOTE(KDragon @ Apr 24 2006, 11:55 AM) [snapback]367834[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Well, I wrote this php page and when i try to load it just sits there saying that it's transferring data from localhost (the server is on my comp). I'm pretty sure the following code is trying to do what I want it to do, which is change the text color from white to black (incremently, which is why I put it in a loop). I would just like to know why it doesn't load and just keeps transfering data.

[code]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
function colorDec($colorNum){
  $colorNum--;
  return $colorNum;
}
?>
<?php $colorNum=255; ?>
<p style="color: rgb(<?php while($colorNum > 0){echo colorDec($colorNum);} $colorNum=255; ?>,<?php while($colorNum > 0){echo colorDec($colorNum);} $colorNum=255; ?>,<?php while($colorNum > 0){echo colorDec($colorNum);} ?>)">This be some text.</p>
</body>
</html>
[/code]
[/quote]


Your not setting $colourNum to its new value hence colurNum is always going to be 255 and your code will execute forever. The easiest fix is to make your method parameter a reference.
[code]
function colorDec(&$colorNum){
  $colorNum--;
  return $colorNum;
}
[/code]

With that said, your code doesn't appear to work and you should start again. take a look at this tutorial which does something similar to what I think you are trying to achieve.

[a href=\"http://www.phpfreaks.com/tutorials/5/0.php\" target=\"_blank\"]Tutorial[/a]

Good Luck!

Share this post


Link to post
Share on other sites
I could be wrong; however it appears that you never exit your while loops. This is may be due to the fact that the variable $colorNum has NOT been declared as a global. Hence in the function it has one value and outside the function it has a different value - might read up on declaring variables global.

[a href=\"http://us3.php.net/global\" target=\"_blank\"]http://us3.php.net/global[/a]

Lite...

Oops! a day late and a dollar short

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.