two php code inside one php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alpdog14
Forum Newbie
Posts: 1
Joined: Thu Nov 18, 2010 1:27 pm

two php code inside one php

Post by alpdog14 »

Ok I am new to php and I have a wordpress blog and I am trying to pull a if-else statement together, that says if a certain field is not null then echo this code, if not show the field, here is how the code is functioning now:

<img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" /> //basically displays an image file we indicate in the YIM field of a user

Now what we want it to do is "If" this field $curauth->yim; is not null "then" display <img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" />

but if it is null we want to pull in some fields in that are already being collected by wordpress and they are also php based like:
$author_name
<?php bloginfo('name'); ?>

So i tried writing a if else statment:

Code: Select all

               <?php
                if ($curauth->yim != null);
  			echo '<img src="' . bloginfo('stylesheet_directory'); '/images/' . $curauth->yim; '" />';
		else
			echo '<div id="author">' . bloginfo($author_name); '/div> <br> <div="title">'  . bloginfo('name'); '</div>'
  	
		?>
Now Dreamweaver is showing a red highlight on the "else" line, not the echo line just on the else line, I then tried to just echo "hello" and else still is highlighted so I am thinking my issue is on the if echo line but do not know what it is. Any help would be most appreciated.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: two php code inside one php

Post by Celauran »

You've got semicolons all over the place that shouldn't be there.

Code: Select all

if ($curauth->yim != null)
{
    echo '<img src="' . bloginfo('stylesheet_directory') . '/images/' . $curauth->yim . '" />';
}
else
{
    echo '<div id="author">' . bloginfo($author_name) . '</div> <br> <div id="title">'  . bloginfo('name') . '</div>';
}
Post Reply