tekrscom Posted April 24, 2007 Share Posted April 24, 2007 I was wondering, if you have several instances in which you use the same method of conversion for all variables from your database to your code, is there a way to effect them all, i.e.; if($any_variable == '0'){$any_variable = "No";} if($any_variable == '1'){$any_variable = "Yes";} or if($any_variable == '0'){$any_variable = "Pending";} if($any_variable == '1'){$any_variable = "Closed";} or if($any_variable == '0'){$any_variable = "";} // Was also curious about this, is there a better way, instead of just using empty quotes, like some way to destroy the variable so it doesn't show anything? if($any_variable == '1'){$any_variable = "Here is whatever";} Its just that when you have to repeat this several times, for several different variables, it seems to make for alot of extra strung around code. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted April 24, 2007 Share Posted April 24, 2007 Was also curious about this, is there a better way, instead of just using empty quotes, like some way to destroy the variable so it doesn't show anything? http://us2.php.net/unset I'm not really sure what the first part of your question is asking. Best, Patirck Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 if you have them with specific $var names... no theres prolly not a better way of getting at them $var names... if you want to destroy $vars... unset($var1,$var2); Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 ohya... also with... if($any_variable == '0'){$any_variable = "No";} if($any_variable == '1'){$any_variable = "Yes";} you prolly want to code it this way... its alot faster ;-)... switch($any_variable){ case "0": $any_variable="No"; break; case "1": $any_variable="Yes"; break; } Quote Link to comment Share on other sites More sharing options...
tekrscom Posted April 24, 2007 Author Share Posted April 24, 2007 Ok, I just wasn't sure if there was a way to look for any variable that equalled 0, then change it to equal something else. Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 i wish! lol Quote Link to comment Share on other sites More sharing options...
tekrscom Posted April 24, 2007 Author Share Posted April 24, 2007 LOL... Thanks for the better code examples, ... My code sometimes is quite barbaric. Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 no prob... happy to be of help :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.