simple if else

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
cauri
Forum Newbie
Posts: 4
Joined: Thu Feb 26, 2004 9:04 am

simple if else

Post by cauri »

Very new to php.
I have a simple if statement but I keep gatting a parse error on the echo statements and I cannot see the fault:

Code: Select all

<?php
			if (is_null($row_rsFoundContacts['subway_link'])) {
   			 	echo "Subway: {$row_rsFoundContacts['subway']}";
 			} else {
				echo "Subway: "<a href='"$row_rsFoundContacts['subway_link']"'>"$row_rsFoundContacts['subway']"</a><br />;
 			}
		?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

This line is a bit foobared:

Code: Select all

echo "Subway: "<a href='"$row_rsFoundContacts['subway_link']"'>"$row_rsFoundContacts['subway']"</a><br />;
you haven't got any concenation and the quoting's a bit shady, try this:

Code: Select all

echo 'Subway: <a href="'.$row_rsFoundContacts['subway_link'].'">'.$row_rsFoundContacts['subway'].'</a><br />';
Mac
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

try this out for size

Code: Select all

<?php 
if (is_null($row_rsFoundContacts['subway_link'])) { 
	echo "Subway: {$row_rsFoundContacts['subway']}"; 
} else { 
	echo "Subway: <a href="".$row_rsFoundContacts['subway_link']."">".$row_rsFoundContacts['subway']."</a><br />"; 
} 
?>
You need to escape your some of your literal quotes with a backslash.

Mark
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

i didn't test it bu i think this should work

Code: Select all

<?php
if (is_null($row_rsFoundContacts['subway_link'])) {
	echo "Subway: {$row_rsFoundContacts['subway']}";
	} else {
		echo "Subway: <a href=".$row_rsFoundContacts['subway_link'].">".$row_rsFoundContacts['subway']."</a><br />";
}
?>
ahh i forgot the \" ... look at the post befor me.. :P
cauri
Forum Newbie
Posts: 4
Joined: Thu Feb 26, 2004 9:04 am

Post by cauri »

thank you. It works now. I'm learning.

cauri
Post Reply