PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 7th, 2002, 08:42 PM
c0rbin c0rbin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Houston, TX, USA
Posts: 8 c0rbin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to c0rbin
What is Wrong w/ this Code??

I am practicing taking code from other scripts (javascript) and reproducing it in PHP. This code produces a hierarchical navigation on the fly based on a CSS and the function sideNav. The background colors alternate depending on the variable $vLevel and the action in the 3rd echo statement within the function // $setCols[ (($rCol % 2) + $vBG) ]) //

Unfortunately, this all works without error except the background color doesn;t display. Further, I cannot get a value for $rCol at all unless I echo it outside of the function code block.

I am a novice and I am having a hard time figuring out A) what is missing and B) what I can do to troubleshoot it.

Code follows...

php Code:
Original - php Code
  1.  
  2.  
  3.  
  4. <html>
  5. <head>
  6.     <title>Test Code</title>
  7. </head>
  8. <LINK REL=STYLESHEET HREF="shellcare.css" TYPE="text/css">
  9. <body bgcolor="#000000">
  10.  
  11.  
  12. <?php
  13.  
  14.  
  15. $rCol = 1;
  16.  
  17. $setCols = array( "#aaaaaa", "#bbbbbb", "#cccccc", "#dddddd", "#eeeeee", "#EFEFEF", "#cc0000", "#CC0000");
  18.  
  19. function sideNav($vLevel, $vLink, $vURL)
  20. {
  21.     if ($vLevel ==1 )
  22.         $vBG = 0;
  23.     if ($vLevel ==2 )
  24.         $vBG = 2;
  25.     if ($vLevel ==3 )
  26.         $vBG = 4;
  27.     echo "<TR><TD width=10 bgcolor=#003366>";
  28.     echo "<font color=#ffcc00><b>></b></TD>";
  29.     echo "<TD BGCOLOR=".$setCols[ (($rCol % 2) + $vBG) ].">";
  30.     echo "<DIV Class=nav".$vLevel.">";
  31.     echo "<a href=".$vURL.">".$vLink."</A>";
  32.     echo "</DIV></TD>";
  33.     $rCol = $rCol + 1;
  34. }
  35. ?>
  36.  
  37.  
  38. <table border="0" cellspacing="1" cellpadding="1" width="143">
  39.  
  40. <td bgcolor="#003366" align="Left"></td>
  41. </tR>
  42.  
  43.  
  44.  
  45.  
  46. <tr>
  47.  
  48. <?php
  49.  
  50. sideNav(1, "Toolkit Home", "index.htm");
  51. sideNav(1, "Toolkit Home", "index.htm");
  52. sideNav(2, "Toolkit Home", "index.htm");
  53. sideNav(2, "Toolkit Home", "index.htm");
  54. sideNav(1, "Toolkit Home", "index.htm");
  55. sideNav(1, "Toolkit Home", "index.htm");
  56. sideNav(2, "Toolkit Home", "index.htm");
  57. sideNav(2, "Toolkit Home", "index.htm");
  58. sideNav(1, "Toolkit Home", "index.htm");
  59. sideNav(2, "Toolkit Home", "index.htm");
  60. sideNav(2, "Toolkit Home", "index.htm");
  61. ?>
  62.  
  63. <td bgcolor="#003366" align="Left"></td></tr>
  64. </table>
  65.  
  66.  
  67.  
  68.  
  69.  
  70. </body>
  71. </html>


Out put: http://www.moontots.com/test/index_test_php.php

Reply With Quote
  #2  
Old November 7th, 2002, 10:29 PM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: What is Wrong w/ this Code??

Why don't you try doing your math

(($rCol % 2) + $vBG)

outside of the string, and make sure your getting a valid value. In other words try:
Code:
function sideNav($vLevel, $vLink, $vURL)
{
    if ($vLevel ==1 )
        $vBG = 0;
    if ($vLevel ==2 )
        $vBG = 2;
    if ($vLevel ==3 )
        $vBG = 4;
    $x=($rCol % 2) + $vBG;
//  echo $x;  You could add this to see what value is being calculated each time.
    echo "<TR><TD width=10 bgcolor=#003366>";
    echo "<font color=#ffcc00><b>></b></TD>";
    echo "<TD BGCOLOR=".$setCols[$x].">";
    echo "<DIV Class=nav".$vLevel.">";
    echo "<a href=".$vURL.">".$vLink."</A>";
    echo "</DIV></TD>";
    $rCol = $rCol + 1;
}
?>

Reply With Quote
  #3  
Old November 8th, 2002, 08:11 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: What is Wrong w/ this Code??

Also, it appears you have no globals in your function, and you're using variables not called to the function itself.

Reply With Quote
  #4  
Old November 8th, 2002, 02:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: What is Wrong w/ this Code??

Thanks Brut, trying that now. And Anonymous, does PHP require I declare variables for functions?

If so, can you give me an example?

Reply With Quote
  #5  
Old November 8th, 2002, 02:22 PM
c0rbin c0rbin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Houston, TX, USA
Posts: 8 c0rbin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to c0rbin
RE: What is Wrong w/ this Code??

It is the variable $rCol that is not registering.

And it is not incrimenting.

Why is that??

Reply With Quote
  #6  
Old November 8th, 2002, 02:49 PM
TylerDurden TylerDurden is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Knoxville, TN USA
Posts: 16 TylerDurden User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: What is Wrong w/ this Code??

PHP does not enforce variable declaration. Which, IMHO, can lead to some sloppy/spaghetti code and a maintenance nightmare when supporting someone else's code.
To answer your question...
Code:
function Whatever() {
  $rCol = 0;  // declared and initialized variable
  .
  .
}

HTH
Quote:
Thanks Brut, trying that now. And Anonymous, does PHP require I declare variables for functions? If so, can you give me an example?


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > What is Wrong w/ this Code??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT