Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-17-2007, 03:14 PM php insice an echo
Skilled Talker

Posts: 69
Trades: 0
Please help me. I cannot get this code to work properly. The web page is not properly showing the php code.

echo "<tr class='text1'><td><?php if(".$emailel."=='email') echo '<a href='mailto:".$userel."'><img src='emaillogo.gif'></a>'; else echo ' '; ?></td><td>".$bus."</td><td>".$busc."</td></tr>";}

The variables are pulled correctly. However, the images are not showing when the email matches.
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-17-2007, 03:24 PM Re: php insice an echo
Extreme Talker

Posts: 217
Trades: 0
Quote:
Originally Posted by weddingm View Post
Please help me. I cannot get this code to work properly. The web page is not properly showing the php code.

echo "<tr class='text1'><td><?php if(".$emailel."=='email') echo '<a href='mailto:".$userel."'><img src='emaillogo.gif'></a>'; else echo ' '; ?></td><td>".$bus."</td><td>".$busc."</td></tr>";}

The variables are pulled correctly. However, the images are not showing when the email matches.
You dont need to start the PHP engine after its already been started. Also, you cant have if statements or anything like that inside a echo, and you cant nest echos inside echos.

Here is a proper way to do it:
PHP Code:
echo "<tr class='text1'><td>";
if(
$emailel == email){
  echo 
"<a href='mailto:$userel'><img src='emaillogo.gif'></a>";
}
else{
  echo 
" ";
}
echo 
"</td><td>$bus</td><td>$busc</td></tr>"
That should clear it up hopefully. If not it might be another problem.
__________________

Please login or register to view this content. Registration is FREE
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 02-17-2007, 07:11 PM Re: php insice an echo
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
It's usually best to limit your usage of using echo for performance reasons, so just store everything in a string first then echo that string:

PHP Code:
<?php
$tmp 
'<tr class="text1"><td>';
if(
$emailel == 'email') {
  
$tmp .= '<a href="mailto:'.$userel.'"><img src="emaillogo.gif"></a>';
else {
  
$tmp .= '&nbsp;';
}
$tmp .= '</td><td>'.$bus.'</td><td>'.$busc.'</td></tr>';
echo 
$tmp;
?>
The only problem I noticed with Slick's code is he was using the constant name email not the string 'email' though if the constant email doesn't exist, PHP assumes the string 'email' but it's poor programming to rely on this.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 02-17-2007 at 07:13 PM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 02-17-2007, 11:33 PM Re: php insice an echo
Extreme Talker

Posts: 217
Trades: 0
actually that was a typo on my part, forgot to put it in single quotes.
__________________

Please login or register to view this content. Registration is FREE
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 02-18-2007, 12:53 AM Re: php insice an echo
Skilled Talker

Posts: 69
Trades: 0
Thanks guys for your help. I got it to work!
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php insice an echo
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27261 seconds with 12 queries