if else trouble

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JD

    if else trouble

    I have the below code that displays a small thumbnail if a user is saluted,
    if they aren't saluted it checks to see if they might have a profile
    picture, this all works with the exception that is no profile picture exist
    it still trys to display a broken image, Im sure it's a simple mistake any
    help please?

    <?php
    if ($commentUser[0]['saluted']=="Yes") {
    ?>
    <img src="../salute/<?php echo $commentUser[0]['login'];
    ?>/thumbs/random.php" border=0 width="50">
    <?php } else { ?>
    <?php if
    ( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {
    ?>
    <img src="../profilepic/<?php echo $commentUser[0]['login'];
    ?>/thumbs/random.php" border=0 width="50">
    <?php } else { ?>
    this part doesn't work
    <?php
    }
    } ?>


  • futureofphp

    #2
    Re: if else trouble

    Hey.. Hi

    Looks like you messed up the code, You can keep it loads neater. The
    code is small and still it gives problems. :-)

    Dont you thinks its better if you can write code like:
    if($commentUser[0]['saluted']=="Yes"){
    echo '********ALL THAT YOU NEED ***';
    }
    else
    {
    echo ' **ALL THE OTHER STUFF';
    }

    Comment

    • Tim Roberts

      #3
      Re: if else trouble

      "JD" <news@aznfetish .com> wrote:
      [color=blue]
      >I have the below code that displays a small thumbnail if a user is saluted,
      >if they aren't saluted it checks to see if they might have a profile
      >picture, this all works with the exception that is no profile picture exist
      >it still trys to display a broken image, Im sure it's a simple mistake any
      >help please?
      >
      ><?php
      > if ($commentUser[0]['saluted']=="Yes") {
      >?>
      > <img src="../salute/<?php echo $commentUser[0]['login'];
      >?>/thumbs/random.php" border=0 width="50">
      ><?php } else { ?>
      ><?php if
      > ( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {[/color]

      You don't want the "!" in there. You're saying if they do NOT have a
      profile directory, then display the profile picture, which is guaranteed
      not to be found.
      [color=blue]
      >?>
      ><img src="../profilepic/<?php echo $commentUser[0]['login'];
      >?>/thumbs/random.php" border=0 width="50">
      ><?php } else { ?>
      >this part doesn't work
      ><?php
      > }
      >} ?>
      >[/color]

      --
      - Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • Tony

        #4
        Re: if else trouble

        JD wrote:[color=blue]
        > I have the below code that displays a small thumbnail if a user is
        > saluted, if they aren't saluted it checks to see if they might have a
        > profile picture, this all works with the exception that is no profile
        > picture exist it still trys to display a broken image, Im sure it's a
        > simple mistake any help please?
        >
        > <?php
        > if ($commentUser[0]['saluted']=="Yes") {[color=green]
        >>[/color]
        > <img src="../salute/<?php echo $commentUser[0]['login'];[color=green]
        >> /thumbs/random.php" border=0 width="50">[/color]
        > <?php } else { ?>
        > <?php if
        > ( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {[color=green]
        >>[/color]
        > <img src="../profilepic/<?php echo $commentUser[0]['login'];[color=green]
        >> /thumbs/random.php" border=0 width="50">[/color]
        > <?php } else { ?>
        > this part doesn't work
        > <?php
        > }
        > } ?>[/color]

        Are you aware of print & echo? It's a lot easier than dropping in & out of
        PHP to output your HTML - and I'll bet your code would be easier to read.

        It's difficult to see what you're trying to do the way it's written.
        Anyways, the same thing, a bit cleaned up:

        <?php
        if ($commentUser[0]['saluted']=="Yes") {
        print "<img src='..salute" . $commentUser[0]['login'] .
        "/thumbs/random.php' border=0 width=50>\n";
        } else {
        if ( !is_dir('.profi lepic' . $commentUser[0]['login']) ) {
        print "<img src='..profilep ic". $commentUser[0]['login'] .
        "/thumbs/random.php' border=0 width=50>\n";
        } else {
        print "<p>this part doesn't work</p>\n";
        }
        }
        ?>

        let's follow the logic:
        1 - you're checking if "saluted" is set, and if so, you display a "saluted"
        picture.
        2 - if "saluted" is NOT set, then you check if for a "profilepic " directory
        based on 'login'.
        a - if that "profilepic " directory does not exist, you try to display an
        image from "profilepic " one directory up from the current
        b - if that "profilepic " directory DOES exist, you want to do something
        (that isn't happening)

        Is that about what you want to have happen?

        What, exactly, IS happening, then? Have you tried just putting in a message
        (like in the code I supplied above), to see if it's even getting to that
        test?

        I suspect that at least some of the problems will go away if you clean up
        the code a bit.

        --
        Tony Garcia
        Web Right! Development
        Riverside, CA



        Comment

        Working...