Jump to content


Photo

Page won't load??


  • Please log in to reply
2 replies to this topic

#1 KDragon

KDragon
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 April 2006 - 01:55 AM

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.

<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>


#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 24 April 2006 - 02:28 AM

[!--quoteo(post=367834:date=Apr 24 2006, 11:55 AM:name=KDragon)--][div class=\'quotetop\']QUOTE(KDragon @ Apr 24 2006, 11:55 AM) View Post[/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.

<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>
[/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.
function colorDec(&$colorNum){
  $colorNum--;
  return $colorNum;
}

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!


#3 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 24 April 2006 - 02:28 AM

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

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users