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? Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/ 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. Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/#findComment-185936 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. Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/#findComment-185939 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(); ?> Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/#findComment-185943 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. Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/#findComment-185944 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. Link to comment https://forums.phpfreaks.com/topic/38707-quick-question/#findComment-185948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.