Unholy Prayer Posted February 16, 2007 Share Posted February 16, 2007 Ok, I'm making an affiliates management program and I want to give the user the option to display their banners either vertically or horizontally. Would it be possible to have an if statement inside of a string? Would something like this work? $display = if($banner_display == horizontal)... { echo " "; } The ... means that there's more but don't feel like writing it. Would that work? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 16, 2007 Share Posted February 16, 2007 That is a standard if statement, so there is no reason it wouldn't work...aside from the part of your code you haven't posted. Quote Link to comment Share on other sites More sharing options...
renj0806 Posted February 16, 2007 Share Posted February 16, 2007 Yes, that should work. If you have problems with what youre doing, you can post your codes here so that we can have a look at it. Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 16, 2007 Share Posted February 16, 2007 Well this doesn't work.. <?php $banner_display = "horizontal"; $display = if($banner_display == "horizontal") { echo "Horizontal"; } echo $display; ?> Parse error: syntax error, unexpected T_IF You can accomplish that with a function. <?php function DisplayType() { $display = "vertical"; if ($display == "horizontal") { echo "Horizontal"; } if ($display == "vertical") { echo "Vertical"; } } DisplayType(); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2007 Share Posted February 16, 2007 If statements do not return anything so you cannot assign a variable to them that way. I still don't really understand the question, explain it in english, not invalid pseudo code. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 16, 2007 Share Posted February 16, 2007 Should have paid more attention before...you aren't assigning a value to $display using your first code example... if you change it to this: <?php $banner_display = "horizontal"; $display = ($banner_display == "horizontal") ? "Horizontal" : "Vertical"; echo $display; ?> It will work. Look in the manual for ternary operators. 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.