goocharlton Posted September 2, 2007 Share Posted September 2, 2007 I have a content area with width that varies according to whether there are left or right modules(this is a joomla cms site). I have written this code but I cant get it to work.... <div id="content" style="width:<?php if ((mosCountModules( "left" )) < 0): if ((mosCountModules( "right" )) < 0) echo "800";; elseif ((mosCountModules( "left" )) > 0): if ((mosCountModules( "right" )) > 0) echo "380";; elseif ((mosCountModules( "left" )) < 0): if ((mosCountModules( "right" )) > 0) echo "590";; elseif ((mosCountModules( "left" )) > 0): if ((mosCountModules( "right" )) < 0) echo "590";; endif; ?>px"> </div> Can anyone tell me what I am doing wrong, if you dont know anything about Joomla do you know whats wrong with the php i have writen?. I am trying to say that: - If there are no modules in the left AND right columns echo a width of 800px. - If there are modules in the left AND right columns echo a width of 380px. - If there are modules in the right AND not in the left columns echo a width of 590px. - If there are modules in the left AND not in the right columns echo a width of 590px. Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/ Share on other sites More sharing options...
matthewhaworth Posted September 2, 2007 Share Posted September 2, 2007 I have a content area with width that varies according to whether there are left or right modules(this is a joomla cms site). I have written this code but I cant get it to work.... <div id="content" style="width:<?php if ((mosCountModules( "left" )) < 0): if ((mosCountModules( "right" )) < 0) echo "800";; elseif ((mosCountModules( "left" )) > 0): if ((mosCountModules( "right" )) > 0) echo "380";; elseif ((mosCountModules( "left" )) < 0): if ((mosCountModules( "right" )) > 0) echo "590";; elseif ((mosCountModules( "left" )) > 0): if ((mosCountModules( "right" )) < 0) echo "590";; endif; ?>px"> </div> Can anyone tell me what I am doing wrong, if you dont know anything about Joomla do you know whats wrong with the php i have writen?. I am trying to say that: - If there are no modules in the left AND right columns echo a width of 800px. - If there are modules in the left AND right columns echo a width of 380px. - If there are modules in the right AND not in the left columns echo a width of 590px. - If there are modules in the left AND not in the right columns echo a width of 590px. <div id="content" style="width:<?php if ((mosCountModules( "left" )) < 0) { if ((mosCountModules( "right" )) < 0) echo "800"; } elseif ((mosCountModules( "left" )) > 0) { if ((mosCountModules( "right" )) > 0) echo "380"; } elseif ((mosCountModules( "left" )) < 0) { if ((mosCountModules( "right" )) > 0) echo "590"; } elseif ((mosCountModules( "left" )) > 0) { if ((mosCountModules( "right" )) < 0) echo "590";; } ?>px"> </div> Your syntax was completely wrong? Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340066 Share on other sites More sharing options...
hostfreak Posted September 2, 2007 Share Posted September 2, 2007 <div id="content" style="width:<?php if ((mosCountModules( "left" )) < 0) { if ((mosCountModules( "right" )) < 0) echo "800"; } elseif ((mosCountModules( "left" )) > 0) { if ((mosCountModules( "right" )) > 0) echo "380"; } elseif ((mosCountModules( "left" )) < 0) { if ((mosCountModules( "right" )) > 0) echo "590"; } elseif ((mosCountModules( "left" )) > 0) { if ((mosCountModules( "right" )) < 0) echo "590";; } ?>px"> </div> Your syntax was completely wrong? Umm... no, his syntax was not completely wrong. I suggest you look into http://www.php.net/manual/en/control-structures.alternative-syntax.php . However, his logic is. Try this: <div id="content" style="width:<?php if ((mosCountModules('left') && mosCountModules('right')) < '0'): echo '800'; elseif ((mosCountModules('right') && mosCountModules('left')) > '0'): echo '380'; elseif ((mosCountModules('left') < '0') && (mosCountModules( "right" ) > '0')): echo '590'; elseif ((mosCountModules('right') < '0') && (mosCountModules( "left" ) > '0')): echo '590'; endif; ?>px"> </div> Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340092 Share on other sites More sharing options...
Timma Posted September 2, 2007 Share Posted September 2, 2007 Just wondering, but don't you have to cut a gaping hole? <<If wondering what the hell I am on about, look for the quotation marks>> echo "<div id='content' style='width:"<?php if ((mosCountModules('left') && mosCountModules('right')) < '0'): echo '800'; elseif ((mosCountModules('right') && mosCountModules('left')) > '0'): echo '380'; elseif ((mosCountModules('left') < '0') && (mosCountModules( "right" ) > '0')): echo '590'; elseif ((mosCountModules('right') < '0') && (mosCountModules( "left" ) > '0')): echo '590'; endif; ?>"px'> </div>"; Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340097 Share on other sites More sharing options...
hostfreak Posted September 3, 2007 Share Posted September 3, 2007 Timma, what exactly are you talking about (cut a gaping hole)? Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340115 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 No idea, I must of picked it up somewhere. Probably is unneeded as people, with strings, usually do something like. "text goes here $var oh look more text" and I go "text goes here ".$var." oh look more text" Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340120 Share on other sites More sharing options...
hostfreak Posted September 3, 2007 Share Posted September 3, 2007 PHP can be embedded in html, so there is no problem with the way he's doing it. Take a look at http://www.php.net/manual/en/language.basic-syntax.php & http://www.php.net/manual/en/language.types.string.php . Hopefully those will give you a better understanding. Your method is fine for strings (<a href="http://www.php.net/manual/en/language.operators.string.php">concatenation operator</a>), but that is kinda irrelevant to this topic. Link to comment https://forums.phpfreaks.com/topic/67694-variable-content-width/#findComment-340134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.