PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 29th, 2003, 09:58 PM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
PHP "else" problem

what is wrong with this?
PHP Code:
<?
$type 
1;

if (
$type 1){
$type2 de;
}

if (
$type 2){
$type2 cs;
}

if (
$type 3){
$type2 = as;
}

if (
$type 4){
$type2 ka;
}

if (
$type 5){
$type2 fy;
}

if (
$type 6){
$type2 dm;
}

if (
$type 7){
$type2 he;
}

if (
$type 8){
$type2 de;
}

echo 
$type2;
?>

Reply With Quote
  #2  
Old August 30th, 2003, 12:09 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
put the values into quotes, you're wanting to store them as string values right?

Reply With Quote
  #3  
Old August 30th, 2003, 12:28 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
ok... First off, Im going to show you a few options you have later on when you get into other types of coding, so you can avoid if logic loops, it'll help reduce load on the server (its only a minute bit but still )

you can do the same thing with a case statement:
PHP Code:
switch ($type){
    case 
1:{
        
$type2 "de";
        break;
    }
    case 
2:{
        
$type2 "cs";
        break;
    }
    case 
3:{
        
$type2 "as";
        break;
    }
    case 
4:{
        
$type2 "ka";
        break;
    }
    case 
5:{
        
$type2 "fy";
        break;
    }
    case 
6:{
        
$type2 "dm";
        break;
    }
    case 
7:{
        
$type2 "he";
        break;
    }
    case 
8:{
        
$type2 "de";
        break;
    }



or.. if you want to go even more advanced, store everything into an array

PHP Code:
 $myvar $_POST['language_number']; //This is where you would get the value 
//of the languaged which should be passed, or similarly 
//you could assign it automatically if you wanted..

//or you could just assign it to 1 like you did above.. whichever

$types = array(
    
=> 'de',
    
=> 'cs',
    
=> 'as',
    
=> 'ka',
    
=> 'fy',
    
=> 'dm',
    
=> 'he',
    
=> 'de',
    
=> 'en'
); //I added english


//if you wanted to know what values you have stored 
//in the array you can always do this:

print_r($types);

$type $types[$myvar]; 


not saying you have to do this, but it's an option ... makes for a lot less typing, and I'm lazy.. hehe

HTH

Last edited by nicat23 : August 30th, 2003 at 12:30 PM.

Reply With Quote
  #4  
Old August 30th, 2003, 06:00 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Going with Nicat's suggestion would be best... But the problem with you code is that you have this:

PHP Code:
if ($type 1){ 


And it should be:

PHP Code:
if ($type == 1){ 


Using a single "=" means you're assigning the value to your variable, rather than comparing them. You should use == when comparing values.

HTH!
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #5  
Old September 2nd, 2003, 06:57 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
And to elaborate on FrankieShakes's post, using the assignment operator (=) instead of the comparison operator (==) should evaluate to true, and your first if will always be executed.

Reply With Quote
  #6  
Old September 2nd, 2003, 10:04 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Thanks for the correction guys See... no one's perfect.. hehe

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP "else" problem


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 2 hosted by Hostway