Web Analytics Made Easy -
StatCounter Can anyone help with an IF/Else statement? - CodingForum

Announcement

Collapse
No announcement yet.

Can anyone help with an IF/Else statement?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can anyone help with an IF/Else statement?

    Please could anyone help me with some php/joomla code.

    I am basically trying to create an if/else statement (i think!) to check if rounded
    "corners-flexable-width" is enabled, or if "rounded corners-fixed-width" is enabled in a joomla module.

    If the flexable-width is enabled in the module, then I want the flexable-width code to output, or if
    the fixed-width is enabled in the module, then I want the fixed-width code to be outputted.

    The code I have is as follows, it outputs both IF statements, I want it to only output the
    statement which is true.

    If that makes sense, Im sorry my php is hopeless and im trying to
    customize some code I came across -
    PHP Code:

    <?php if($this->roundedflexablewidth):?>
    <div class="roundedflexablewidth">
    <div>
    <div>
    <div>
    <?php endif; ?>             

    <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

    <?php if($this->roundedflexablewidth):?>                
    </div>
    </div>
    </div>
    </div>
    <?php endif; ?> 
          
    "If flexable width isnt enabled in the module, then display the following -" 
              
    <?php if($this->roundedfixedwidth):?>
    <div class="roundedfixedwidth">
    <div>
    <?php endif; ?>             
    <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

    <?php if($this->roundedfixedwidth):?>                
    </div>
    </div>
    <?php endif; ?>
    Last edited by moss2076; Apr 10, 2009, 06:33 PM.

  • #2
    You're making the assumption that both variables can't be true at the same time. Evidently they are.

    Comment


    • #3
      Yes that is why I need some help with the code, like I said, my php is useless and I need some help to correct it so one statement is true, then ignore the other, if that makes sense.

      Comment


      • #4
        Yes that makes sense. You'll need to determine which one has priority over the other, and then simply nest the lower priority setting's "if" block inside the hight priority setting's "if" block.

        PHP Code:
        if ($first_priority_setting == true) {
            
        //do stuff for first priority
        } else {
            if (
        $second_priority_setting == true) {
                
        //do stuff for second priority
            
        }

        This will catch the first priority setting first, and if it's true then it will only do that stuff. If it's not true, then it will check the second priority setting and do that stuff if it's true.

        Comment


        • #5
          Originally posted by Fumigator View Post
          Yes that makes sense. You'll need to determine which one has priority over the other, and then simply nest the lower priority setting's "if" block inside the hight priority setting's "if" block.

          PHP Code:
          if ($first_priority_setting == true) {
              
          //do stuff for first priority
          } else {
              if (
          $second_priority_setting == true) {
                  
          //do stuff for second priority
              
          }

          This will catch the first priority setting first, and if it's true then it will only do that stuff. If it's not true, then it will check the second priority setting and do that stuff if it's true.
          Ok this sounds good, but I am a toal dweeb when it comes to php, so sorry if Im sounding dumb

          So if Roundedflexablewidth is true, display it
          else
          if Roundedfixedwidth is true, display it

          That sounds straight forward enough, but I dont know where to put what in my code

          Comment


          • #6
            PHP Code:
            <?php if($this->roundedflexablewidth):?>                
            </div>
            </div>
            </div>
            </div>
            <?php elseif($this->roundedfixedwidth):?>
            <div class="roundedfixedwidth">
            <div>
            <?php elseif($this->roundedfixedwidth):?>             
            </div>
            </div>
            <?php endif;?>
            and link to doc: http://www.phpbuilder.com/manual/en/...n.if-endif.php

            but I think there is some logical problem in script... there is two IF statement with the same condition... so if they are the same why we need two of them?

            Comment


            • #7
              Here is what I have so far, it is "sort of" working, in that the correct divs are outputting as they should, BUT the actual content of the div which IS'NT to be displayed is still displaying.

              Here is what I have -
              PHP Code:

              <?php if($this->roundedflexablewidth):?> 
              <div class="roundedflexablewidth"> 
              <div> 
              <div> 
              <div> 
              <?php endif; ?>              

              <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

              <?php if($this->roundedflexablewidth):?>                
              </div>
              </div>
              </div>
              </div>
              <?php elseif($this->roundedfixedwidth):?>
              <div class="roundedfixedwidth">
              <div>
              <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

              <?php elseif($this->roundedfixedwidth):?>             
              </div>
              </div>
              <?php endif;?>
              So, if "roundedfixedwidth" is the option to be displayed its divs and content are ok, but the content of "roundedflexablewidth" is still also being displayed on its own as well -
              PHP Code:
              <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

              Comment


              • #8
                You are not right... based on the first code at list that line:
                PHP Code:
                <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                was outside of the IF statement while in your last sample you have moved it inside... just pay attention to the difference:
                PHP Code:
                ...
                <?php elseif($this->roundedfixedwidth):?>
                <div class="roundedfixedwidth">
                <div>
                <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

                <?php elseif($this->rounded
                ...
                is not the same as:
                PHP Code:
                ...
                <?php if($this->roundedfixedwidth):?>
                <div class="roundedfixedwidth">
                <div>
                <?php endif; ?>             
                <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

                <?php if($this->rounded
                ...

                Comment


                • #9
                  Im still not winning with this..I know this code isnt working, please can you help? Here is what I have, but I know its not right, its doing my head in! -
                  PHP Code:

                  <?php if($this->roundedflexablewidth):?> 
                  <div class="roundedflexablewidth"> 
                  <div> 
                  <div> 
                  <div> 
                  <?php endif; ?>              

                  <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

                  <?php if($this->roundedflexablewidth):?>                 
                                  
                  </div>
                  </div>
                  </div>
                  </div>
                  <?php elseif($this->roundedfixedwidth):?>
                  <div class="roundedfixedwidth">
                  <div>
                  <?php elseif($this->roundedfixedwidth):?>             
                  </div>
                  </div>
                  <?php endif;?>

                  Comment


                  • #10
                    I think I may have got it to work -
                    PHP Code:

                    <?php if($this->roundedflexablewidth):?> 
                    <div class="roundedflexablewidth"> 
                    <div> 
                    <div> 
                    <div> 

                    <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                    <?php 
                    endif; ?>              

                    <?php if($this->roundedflexablewidth):?>                
                    </div>
                    </div>
                    </div>
                    </div>

                    <?php elseif($this->roundedfixedwidth):?>
                    <div class="roundedfixedwidth">
                    <div>

                    <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

                    <?php elseif($this->roundedfixedwidth):?>             
                    </div>
                    </div>
                    <?php endif;?>
                    Im sorry my knowledge of php isnt up to much, could you let me know what you think of this block of code? Am I on the right track?

                    Comment


                    • #11
                      Ok I will do that for you but just post the original code which you want to change. Because the code which you posted at the beginning has some logical mistakes...

                      IMHO if that is not written by some 'pro' software developer than he/she should stop software development and move back to the level of logic...

                      Comment


                      • #12
                        The code I started with was the original code, I didnt write it -
                        PHP Code:
                        <?php if($this->roundedflexablewidth):?> 
                        <div class="roundedflexablewidth"> 
                        <div> 
                        <div> 
                        <div> 
                        <?php endif; ?>              

                        <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

                        <?php if($this->roundedflexablewidth):?>                 
                        </div> 
                        </div> 
                        </div> 
                        </div> 
                        <?php endif; ?>  
                               
                        "If flexable width isnt enabled in the module, then display the following -"  
                                   
                        <?php if($this->roundedfixedwidth):?> 
                        <div class="roundedfixedwidth"> 
                        <div> 
                        <?php endif; ?>              
                        <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

                        <?php if($this->roundedfixedwidth):?>                 
                        </div> 
                        </div> 
                        <?php endif; ?>
                        But this code below seems to be working -
                        PHP Code:
                        <?php if($this->roundedflexablewidth):?>  
                        <div class="roundedflexablewidth">  
                        <div>  
                        <div>  
                        <div>  

                        <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 
                        <?php endif; ?>               

                        <?php if($this->roundedflexablewidth):?>                 
                        </div> 
                        </div> 
                        </div> 
                        </div> 

                        <?php elseif($this->roundedfixedwidth):?> 
                        <div class="roundedfixedwidth"> 
                        <div> 

                        <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?> 

                        <?php elseif($this->roundedfixedwidth):?>              
                        </div> 
                        </div> 
                        <?php endif;?>
                        Last edited by moss2076; Apr 11, 2009, 04:55 PM.

                        Comment


                        • #13
                          It is working because you are lucky I will rewrite the original code based on the last code:

                          PHP Code:
                          <?php if($this->roundedflexablewidth):?>  
                          <div class="roundedflexablewidth">  
                          <div>  
                          <div>  
                          <div>  
                          <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                          <?php 
                          endif; ?>               

                          <?php if($this->roundedflexablewidth):?>                  
                          </div>  
                          </div>  
                          </div>  
                          </div>  
                          <?php endif; ?>   
                                  
                                      
                          <?php if($this->roundedfixedwidth):?>  
                          <div class="roundedfixedwidth">  
                          <div>  
                          <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                          <?php 
                          endif; ?>               

                          <?php if($this->roundedfixedwidth):?>                  
                          </div>  
                          </div>  
                          <?php endif; ?>
                          As you can see all lines:

                          PHP Code:
                          <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                          where moved inside IF statement. I guess you need to output that lines anyway despite the fact what value IF statement will have

                          PHP Code:
                          <?php if($this->roundedflexablewidth):?>   
                          <div class="roundedflexablewidth">   
                          <div>   
                          <div>   
                          <div>   
                          <?php endif; ?>                

                          <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

                          <?php if($this->roundedflexablewidth):?>                  
                          </div>  
                          </div>  
                          </div>  
                          </div>  
                          <?php elseif($this->roundedfixedwidth):?>  
                          <div class="roundedfixedwidth">  
                          <div>  
                          <?php elseif($this->roundedfixedwidth):?>               
                          </div>  
                          </div>  
                          <?php endif;?>

                          <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>

                          Comment


                          • #14
                            Thankyou for providing the code, but the lines -
                            PHP Code:
                            <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                            need to remain inside the IF statements like this -
                            PHP Code:
                            <?php if($this->roundedflexablewidth):?>  
                            <div class="roundedflexablewidth">  
                            <div>  
                            <div>  
                            <div>  
                            <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                            <?php 
                            endif; ?>               

                            <?php if($this->roundedflexablewidth):?>                  
                            </div>  
                            </div>  
                            </div>  
                            </div>  
                            <?php endif; ?>   
                                    
                                        
                            <?php if($this->roundedfixedwidth):?>  
                            <div class="roundedfixedwidth">  
                            <div>  
                            <?php if(isset($news_code_html_tab[(($b*$this->news_column)+$c)]))echo $news_code_html_tab[(($b*$this->news_column)+$c)];?>
                            <?php 
                            endif; ?>               

                            <?php if($this->roundedfixedwidth):?>                  
                            </div>  
                            </div>  
                            <?php endif; ?>
                            If I move them outside of the code as in your example, then both copies of that line is outputted regardless of which div class is outputted. I have had to keep the line of code inside the IF statement, so only one copy of the code is outputted with the correct div class.

                            The code is for a Joomla module, which lets me select either roundedfixed (2 divs), or roundedflexable (4 divs) corners. I select either in the Joomla module manager for that module, so I only need one copy of that particular line displayed inside whichever div class is selected.

                            It seems to be working fine keeping the line of code inside the IF statements, so Im happy with it
                            Last edited by moss2076; Apr 12, 2009, 12:06 PM.

                            Comment


                            • #15
                              So that is what I am speaking about code which you posted at the beginning has logical errors. You have to say that you need a help not just how to write ELSEIF statement but the logic as well. Ok, now I will read your question again and I will try to find solution.

                              Comment

                              Working...
                              X