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

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 February 23rd, 2007, 05:37 AM
seibetsu seibetsu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 seibetsu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP Switch() Issue

Hello!
I have browsed the site a while for a solution to my problem but I have not been so lucky.

Today I loaded Apache 2 and PHP5. I set up the config for apache and was able to successfully get a page to display
php Code:
Original - php Code
  1. <?phpinfo()?>


With that I wanted to test my new found knowledge with the Switch() statement.

So I grabbed this code from the offical php site,
php Code:
Original - php Code
  1. <?php
  2. switch ($i):
  3. case 0:
  4.    echo "i equals 0";
  5.    break;
  6. case 1:
  7.    echo "i equals 1";
  8.    break;
  9. case 2:
  10.    echo "i equals 2";
  11.    break;
  12. default:
  13.    echo "i is not equal to 0, 1 or 2";
  14. endswitch;
  15. ?> 


Whenever I run the php page, say switchtest.php?i=1 or switchtest.php?i=5555 , I always get back " i equals 0 ".

I am confused as to why every switch I write / copy always gives me the first case, or the default case. (I tried another switch where all it would do is give me default.)

Now I'm sure this is valid code, since it came from the source, so what sort of things outside of my php page could be the problem?

Thanks very much for your reply. I think I'm up to 5hours on working with this problem.

Reply With Quote
  #2  
Old February 23rd, 2007, 12:43 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: PHP Switch() Issue

The variable $i must be set someplace in the code prior to the switch(...) statement.

Putting ?i=somevalue on the end of the URL would only set the variable $i in your program if you had a statement like the following -

$i = $_GET['i'];

Reply With Quote
  #3  
Old February 23rd, 2007, 07:16 PM
seibetsu seibetsu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 seibetsu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: PHP Switch() Issue

Out of all the code I read and sample tutorials I never saw that line of code. Even in the "working" example pages I downloaded and tested, all of them failed. However it works perfectly now that I've added that code.

Its funny but I remember reading about the get and post commands but at the time didn't quite understand their importance.

Thanks for the information!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Installation > PHP Switch() Issue


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