[SOLVED] echo Dynamic data links ?

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
frogontop
Forum Newbie
Posts: 4
Joined: Sat Mar 13, 2004 10:59 pm

[SOLVED] echo Dynamic data links ?

Post by frogontop »

Hey All, here is the problem (other than the fact I started learning php yesterday! Newbie Alert!),

I've built a recordset which repeats listing all the data records, Got this working no problem. The problem I'm running into is two data types.
email & url.

I've got a simple data verifier which places "N/A" in the field if the mySQL field is = "". No Problem Here is a sample of that code.

Code: Select all

<?php if ($row_profiles['phone']=="") { echo 'N/A';} else { echo $row_profiles['phone'];} ?>
The problem is for the email and url fields I need it to echo a string of code to place the href and mailto links if the data is not null. I had no problem creating the dynamic links without the if statement, but I want N/A to be displayed if the data field is empty. I can do each of these tasks seperatley, but mixed with the if statement and it falls apart!
This is what I've tried, but it's not working.

Code: Select all

<?php if ($row_profiles['email']=="") { echo 'N/A';} else { echo '<a href="mailto:<?php echo $row_profiles['email']?>">$row_profiles['email']?>"></a>';}?>
Because of stupidity reasons on my end it's not working. I'm assuming I have incorrect statements or structure.

Any help would be greatly appreciated.
FrogOnTOp
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: echo Dynamic data links ?

Post by TheBentinel.com »

frogontop wrote:

Code: Select all

<?php if ($row_profiles['email']=="") { echo 'N/A';} else { echo '<a href="mailto:<?php echo $row_profiles['email']?>">$row_profiles['email']?>"></a>';}?>
I think you want something more like:

Code: Select all

<?php 
  if ($row_profiles['email']=="") 
  { 
    echo 'N/A';
  } 
  else 
  { 
    echo '<a href="mailto:' . $row_profiles['email'] . '">' . $row_profiles['email'] . '</a>';
  }
?>
In PHP the string concatenation character is "."

So when you think: echo 'this forum is ' + $LATEST_COOL_WORD ;

Instead type: echo 'this forum is ' . $LATEST_COOL_WORD ;
frogontop
Forum Newbie
Posts: 4
Joined: Sat Mar 13, 2004 10:59 pm

Post by frogontop »

Thanks for the help, worked like a charm!!!! :D
Post Reply