Jump to content

Page won't load??


KDragon

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]
Link to comment
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!
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.