Click to See Complete Forum and Search --> : show link in php..


bolty2uk
10-11-2007, 10:53 AM
hello..

i have a quick query and i would appreciate it very much if someone could give me some advice or point me to a tutorial/guide that details this..

I have a mysql database and in that i have a users website and contact details..
when i display them on the page i use this code to make there details linkable..

<a href="<?php echo $website; ?>" target="_blank">website</a> | <a href="mailto:<?php echo $email; ?>?subject=Enquiry sent via my website" >contact</a>

Now the problem i have is if a user hasnt put in a email or website or both then these links will still be there but wont work..

So what i am after is a way of displaying n/a if i dont have these details..

after doing a bit of reading up i tried this..

<a href="<?php echo $website; ?>" class="style3" target="_blank"><?php echo 'website';if (empty($website)) echo 'N/A'; ?></a>

but this will show 'websiteN/A'..

so i am after a few ideas on how best to achieve this, so basically if the database hasnt got any info for the user it will display n/a..

many thanks for any responces.

:)

Webjedikungfu
10-11-2007, 01:57 PM
Build the link tag in the conditional, if the info is in database it builds it. If not it saya "n/a":
<?php

if (empty($website)) {

$websVar = "n/a";

} else {

$websVar = "<a href=\"$website\">Click here to go to link</a>";

}
?>
<html>

<body>

<?php
echo "$websVar";
?>

</body>

</html>