Jump to content

else statement will not execute?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
hey guys,

I have this php if/else block:

$myvar = $getSearch['u_name'];

			$mytrim=trim($myvar);

			if(!empty($mytrim))

			{

				?>

				<table class="contentOther">

				   <tr>

				      <td class="tableHead">

                         <center>

					     	Results for user search: <?php echo $param; ?>

                         </center>

					  </td>

				   </tr>

                   <tr>

                      <td>

                         <?php

						    if(!empty($getSearch['u_avatar']))

							{

						?>

                                <img src="<?php echo $getSearch['u_avatar']; ?>" border="0" class="avatar" />

                        <?php

							}

						?>

                             <a href="send_mail.php?u_name=<?php echo $getSearch['u_name']; ?>">

             				 	 <img src="Images/led-icons/envelope.png" border="0" alt="Send a private message" />

           					 </a>

          

          					 <a href="viewProfile.php?u_name=<?php echo $getSearch['u_name']; ?>">

          						 <img src="Images/led-icons/user.png" border="0" alt="Go to users profile" />

         					 </a>

          

          						<img src="Images/led-icons/heart.png" border="0" alt="Send frined request" />

         					   <img src="Images/led-icons/yim.png" border="0" alt="Send an instant messange on Yahoo!" />

        					   <img src="Images/led-icons/aim.png" border="0" alt="Send an instant messange on AOL" />

         					   <img src="Images/led-icons/msn.png" border="0" alt="Send an instant messange on MSN" />	

                      </td>

                   </tr>

                   </table>

				   <?php

			}

			else

			{

				echo "User does not exsist";

			}

			


when u_name is an exsisting value it works fine. When it is not an exsisting value it displays nothing at all. I thought maybe it was Zend acting up again but when it is Zend being dumb it goes away after a few days and it did not this time.
Posted Image

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Lets just clean it up a bit. From what I can tell it has no choice to display something that is why its called "else" is there any other code you are not showing us?

<?PHP
            if(!empty(trim($getSearch['u_name'])))
            {
                ?>
                <table class="contentOther">
                   <tr>
                      <td class="tableHead">
                         <center>
                             Results for user search: <?php echo $param; ?>
                         </center>
                      </td>
                   </tr>
                   <tr>
                      <td>
                         <?php
                            if(!empty($getSearch['u_avatar']))
                            {
                        ?>
                                <img src="<?php echo $getSearch['u_avatar']; ?>" border="0" class="avatar" />
                        <?php
                            }
                        ?>
                             <a href="send_mail.php?u_name=<?php echo $getSearch['u_name']; ?>">
                                   <img src="Images/led-icons/envelope.png" border="0" alt="Send a private message" />
                                </a>
          
                               <a href="viewProfile.php?u_name=<?php echo $getSearch['u_name']; ?>">
                                   <img src="Images/led-icons/user.png" border="0" alt="Go to users profile" />
                              </a>
          
                                  <img src="Images/led-icons/heart.png" border="0" alt="Send frined request" />
                                <img src="Images/led-icons/yim.png" border="0" alt="Send an instant messange on Yahoo!" />
                               <img src="Images/led-icons/aim.png" border="0" alt="Send an instant messange on AOL" />
                                <img src="Images/led-icons/msn.png" border="0" alt="Send an instant messange on MSN" />    
                      </td>
                   </tr>
                   </table>
                   <?php
            }
            else
            {
                echo "User does not exsist";
            }


#3
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
your "{" and "}"
doesnt have closing and opening

if statement closing in different php code
and his else on the other php code i think...

>.> just noticed...

proper closing and opening tags is the problem i think >.>

#4
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
@blain - yah there is more code, a series of if statements all nested. I did not post it because the rest of the code works and it has nothing to do with this. There is also the MySQL, but again it is not relaven sense the if statement works we know that the MySQL works. It is only the else statement that dose not work. So I would asume that means it is executing the if statement no matter what. It has to be something I did in the paramater of the if statement but I've looked and looked and I just don't see it. I looked in the source code and it is displaying nothing so the trim should make the veriable empty, I have done it that way several times before and it has always worked. I have also tried doing if NULL but it had the same results (figured it would, but was worth a shot)

Note: if(!empty(trim($getSearch['u_name']))) won't work blain. Thats why I had so many usless steps in there. I origianily had it like that and had to step throu all my code to figure out that line was what prevented my code from doing anything at all. (I know odd. for some reason it won't let me trim any value that is displaied via an array).

@ Hardinera - all the opening and closeing brackets are there. I just went throu with dreamweaver and used balance braces to check.
Posted Image

#5
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Does it not execute the if statement at all? Or does it ignore it sometimes? You have to get some output from it in the else/if statements unless something further up doesnt let you get there. If you are and the logic is a bit wrong maybe its how your doing the if part, what are possible instances of the variable? You might try checking it with strlen might work better

#6
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
The if statement executes. It is the else statement that dosent. Presuming that you ment else statement, no it never executes it. Thats why I belive it to be a problem with the if statement.

The veriable is an array created by mysql_fetch_array() if nothing is returned trim strips out any white space to prevent a false positive. If a value is returned it displays that users information. if nothing is returned it should display user does not exsist.

I tried your sugestion and it gave me the same results.

I just tried taking the not operator out of my if statement just to make sure once again that it wasnt my comp acting up. It's not, when i took it out the else statement executed. The weird thing is that when i did that if i search a non exsistant user it is returning an empty and executing the if statement..... I think I will put the content of the if statement into the else statement and viseversa sense it is working the way i want that way ...... if anyone has an explanation for this I would love to hear it.

Edit: almost forgot. Thanks for the help ya'll

Edit: Never mind. It isn't doing anything. I tested the wrong page. The else statement is executing withought the ! but if empty it still gives a blank page
Posted Image

#7
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
[ATTACH]1863[/ATTACH]

code attatched

Attached Files


Posted Image