Page 1 of 1

[SOLVED] echo Dynamic data links ?

Posted: Sat Mar 13, 2004 10:59 pm
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

Re: echo Dynamic data links ?

Posted: Sat Mar 13, 2004 11:33 pm
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 ;

Posted: Sat Mar 13, 2004 11:40 pm
by frogontop
Thanks for the help, worked like a charm!!!! :D