if statement syntax is wrong

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
mgason
Forum Newbie
Posts: 5
Joined: Thu Jun 24, 2010 11:52 am

if statement syntax is wrong

Post by mgason »

Hi,
I am no PHP expert. I can poke about, do a little cut and paste.
Dreamweaver is telling me I have a syntax issue with my if statement. I have tried a few things without success.
Dreamweaver says the error is on the else line, that may not be true. please show me what I am doing wrong.
Thanks Mark

Code: Select all

<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
				 $block_1 = get_custom_field('cft_tinymce_1');
				if( $block_1 ) { ?>
					<?php echo $block_1; ?> 
						<?php } ?>
						<?php else { ?>
							<?php the_content(); ?>
						<?php } ?>
					</div> <!-- End tec-event-entry -->
mgason
Forum Newbie
Posts: 5
Joined: Thu Jun 24, 2010 11:52 am

Re: if statement syntax is wrong

Post by mgason »

I may have sorted it out, is this the best way, is it correct

Code: Select all

					<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
				 $block_1 = get_custom_field('cft_tinymce_1');
				if( $block_1 ) { ?>
					<?php echo $block_1; ?> 
						<?php } else { ?>
							<?php the_content(); ?>
						<?php } ?>
					</div> <!-- End tec-event-entry -->
fird01
Forum Newbie
Posts: 19
Joined: Mon Apr 07, 2008 11:04 pm

Re: if statement syntax is wrong

Post by fird01 »

may be u shouldn't trust dw so much.. i dont see any difference there
mgason
Forum Newbie
Posts: 5
Joined: Thu Jun 24, 2010 11:52 am

Re: if statement syntax is wrong

Post by mgason »

Hi,
yes I thought the difference is possibly still OK.

Code: Select all

<?php } ?>
                    <?php else { ?>
became this with less PHP tags

Code: Select all

<?php } else { ?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: if statement syntax is wrong

Post by social_experiment »

fird01 wrote:may be u shouldn't trust dw so much.. i dont see any difference there
I concur with fird01.

The code sample can easily be simplified to following below. Dreamweaver probably has it's reasons for using that specific format for producing the code though (however curious).

Code: Select all

<?php 
 /** Get the "cft_tinymce_1" custom field */
 $block_1 = get_custom_field('ctf_tinymce_1');
 if ($block_1) {
 echo $block_1;
 }
 else {
  the_content();
 }
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: if statement syntax is wrong

Post by Jade »

Dreamweaver does that so you can add formatting between the case statements without it having to refractor the <?php code tags so it works properly. My suggestion: don't use Dreamweaver for anything other than building the layout and do all your PHP work after the fact.
Post Reply