Loading ...
Sorry, an error occurred while loading the content.

Re: [phpXperts] Help with If else if

Expand Messages
  • Gu®u
    I tried every possible ways of putting if else if conditions but the issue is although both the images are appearing only those images are taking me to the FB
    Message 1 of 10 , Mar 13, 2012
    • 0 Attachment
      I tried every possible ways of putting if else if conditions but the issue is although both the images are appearing only those images are taking me to the FB or Twitter page who actually has a link in the database. Now I am confused at this point in time but I guess there is something to do with img src not with the $search-> variable.

      Shiplu, I have tried the code from both ends like if empty and if not empty, I guess you understand the situation how frustrating this issue as we all know in the end it will be like some kind of silly error like a (.) dot error, if you know C language you will understand.



      On Wed, Mar 14, 2012 at 1:50 AM, shiplu <shiplu.net@...> wrote:
       

      When you post any code paste it to pastebin type services and then use link. Also don't forget to beautify your code. 
      I have pasted your code on http://pastie.org/3587969 after beautifying. 

      Problem with your code was

      1. Logical error. Your else-if condition will never be true. When the execution point reaches to *else-if* the format *if* is already false. Hence the *else-if* will be false too as you use the very same condition in it.  $search->facebook->ListViewValue() == ""

      2. You tested it as "if a field is empty" while it should be "if the filed is not empty".  Also in the mail you said, "What I want is if the field is empty don't show the image". But isn't it easier to say "What I want to show the non-empty fields".  A condition should state what the state when the next code block will execute not the otherwise.

      The following code works but is not readable at first glance
      if(!$foo){
          // don't do anything
      }else{
         $baz = bar($foo);
      }

      But see this one. any developer knows what it means at a first glance
      if($foo){
          $baz = bar($foo);
      }

      I guess, here is what you need.

      <?php
      $plugin = $search->plugin->ListViewValue();
      $fbook = $search->facebook->ListViewValue();
      if ($plugin && $fbook) {
          echo '<a href="' . $plugin . '"><img src="images/twitter.gif" width="22" height="23"/></a></a>' . '<a href="' . $fbook. '"><img src="images/facebook.gif" width="22" height="23"/></a></a>';
      } else if ($fbook) {
          echo '<a href="' . $fbook . '"><img src="images/facebook.gif" width="22" height="23"/></a></a>';
      } else if ($plugin) {
          echo '<a href="' . $plugin . '"><img src="images/twitter.gif" width="22" height="23"/></a></a>';
      ?>

      I'd have written this like http://pastie.org/3588224

      --
      Shiplu.Mokadd.im
      ImgSign.com | A dynamic signature machine

      Innovation distinguishes between follower and leader




      --
      Best,
      Gu®u

    • shiplu
      Is your problem solved? Did you try this code http://pastie.org/3591299 -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes
      Message 2 of 10 , Mar 13, 2012
      • 0 Attachment
        Is your problem solved? Did you try this code http://pastie.org/3591299

        --
        Shiplu.Mokadd.im
        ImgSign.com | A dynamic signature machine

        Innovation distinguishes between follower and leader

      • Gu®u
        I tried this too however if I am echoing out only variable with HREF (which is a text link) is working. For example, if I remove IMG SRC tag from your code its
        Message 3 of 10 , Mar 13, 2012
        • 0 Attachment
          I tried this too however if I am echoing out only variable with HREF (which is a text link) is working.

          For example, if I remove IMG SRC tag from your code its giving me exactly what I want like if $search->facebook->ListViewValue() is empty its showing me nothing and vice versa but the issue comes when I want to put tweeter OR FB image and HREF with its respective link urls.



          On Wed, Mar 14, 2012 at 11:12 AM, shiplu <shiplu.net@...> wrote:
           

          Is your problem solved? Did you try this code http://pastie.org/3591299



          --
          Shiplu.Mokadd.im
          ImgSign.com | A dynamic signature machine

          Innovation distinguishes between follower and leader




          --
          Best,
          Gu®u

        • shiplu
          What is the HTML output when you use this http://pastie.org/3591494 code? And what is your expected output? -- Shiplu.Mokadd.im ImgSign.com | A dynamic
          Message 4 of 10 , Mar 13, 2012
          • 0 Attachment
            What is the HTML output when you use this http://pastie.org/3591494 code?
            And what is your expected output?


            --
            Shiplu.Mokadd.im
            ImgSign.com | A dynamic signature machine

            Innovation distinguishes between follower and leader

          • Gu®u
            The HTML Output is attached below. What I want is if there is no data in the database for twitter the twitter button should not be appeared in HTML output and
            Message 5 of 10 , Mar 13, 2012
            • 1 Attachment
            • 65 KB
            The HTML Output is attached below. What I want is if there is no data in the database for twitter the twitter button should not be appeared in HTML output and the same for FB too. But right now even if the twitter has no data in the database its coming in the HTML output.



            On Wed, Mar 14, 2012 at 12:08 PM, shiplu <shiplu.net@...> wrote:
             

            What is the HTML output when you use this http://pastie.org/3591494 code?
            And what is your expected output?




            --
            Shiplu.Mokadd.im
            ImgSign.com | A dynamic signature machine

            Innovation distinguishes between follower and leader




            --
            Best,
            Gu®u

          • shiplu
            This is not html. Its the webpage after html is rendered. What is the source of this? -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation
            Message 6 of 10 , Mar 14, 2012
            • 0 Attachment
              This is not html. Its the webpage after html is rendered. 
              What is the source of this?
              --
              Shiplu.Mokadd.im
              ImgSign.com | A dynamic signature machine

              Innovation distinguishes between follower and leader

            • Gu®u
              The HTML you are asking is a php file. However its too huge also its connected with 7 other php files so its highly impossible to send or paste it on
              Message 7 of 10 , Mar 14, 2012
              • 0 Attachment
                The HTML you are asking is a php file. However its too huge also its connected with 7 other php files so its highly impossible to send or paste it on http://pastie.org. However to get you more info about it, its a piece of search engine code. However I am sending you the table which I guess will be useful for more detail of this issue in depth. Here it is:
                 http://pastie.org/3591755



                On Wed, Mar 14, 2012 at 12:31 PM, shiplu <shiplu.net@...> wrote:
                 

                This is not html. Its the webpage after html is rendered. 
                What is the source of this?
                --
                Shiplu.Mokadd.im
                ImgSign.com | A dynamic signature machine

                Innovation distinguishes between follower and leader




                --
                Best,
                Gu®u

              • Gu®u
                Hi All, I have taken the if else to another seprate file just to see if it works with simple data display but the issue is same. Please see this code.
                Message 8 of 10 , Mar 15, 2012
                • 0 Attachment
                  Hi All, I have taken the if else to another seprate file just to see if it works with simple data display but the issue is same. Please see this code. http://pastie.org/3605972.



                  On Wed, Mar 14, 2012 at 1:20 PM, Gu®u <nagendra802000@...> wrote:
                  The HTML you are asking is a php file. However its too huge also its connected with 7 other php files so its highly impossible to send or paste it on http://pastie.org. However to get you more info about it, its a piece of search engine code. However I am sending you the table which I guess will be useful for more detail of this issue in depth. Here it is:
                   http://pastie.org/3591755




                  On Wed, Mar 14, 2012 at 12:31 PM, shiplu <shiplu.net@...> wrote:
                   

                  This is not html. Its the webpage after html is rendered. 
                  What is the source of this?
                  --
                  Shiplu.Mokadd.im
                  ImgSign.com | A dynamic signature machine

                  Innovation distinguishes between follower and leader




                  --
                  Best,
                  Gu®u




                  --
                  Best,
                  Gu®u

                Your message has been successfully submitted and would be delivered to recipients shortly.