Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...What you have done for people like me is immeasurably helpful."

Geography

Where in the world do Tek-Tips members come from?

Special Fields Turned on or off with Conditional StatementsHelpful Member! 

followtheboat (Programmer)
10 Dec 08 17:16
I've used some special fields which I would like to call up only if they have a record against them. At the moment all I have is the echo for them - I'm unsure how to wrap them in a conditional statement i.e. if the record exists then echo it, if not then don't show anything. Here is the code currently:

CODE

    

<div class="logbookpositionl">
      <?php the_time('d F, Y') ?><br><br>
      <?php $key="leg"; $value =get_post_meta($post->ID, $key, true); echo "".$value;?><br><br>      
      <?php $key="lat"; $value =get_post_meta($post->ID, $key, true); echo "".$value;?><br>
      <?php $key="lon"; $value =get_post_meta($post->ID, $key, true); echo "".$value;?>
    </div>
<div class="logbookpositionr">
     <?php $key="vessel"; $value =get_post_meta($post->ID, $key, true); echo "Vessel: ".$value;?><br><br>
      <?php $key="distance"; $value =get_post_meta($post->ID, $key, true); echo $value." nautical miles";?> <br><br>
      <?php $key="weather"; $value =get_post_meta($post->ID, $key, true); echo "Weather: ".$value;?>       
    </div>

You can see in the second section I have included some descriptive text. At the moment this is being echoed irrespective of the fact there isn't a record in there.

I'm pretty new to PHP so any help would be gratefully received.

Thanks in advance.
Helpful Member!  BillyRayPreachersSon (Programmer)
11 Dec 08 2:43

You should be able to prefix your echo statements with an if statement, something like this:

CODE

<?php
    $key = "distance";
    $value = get_post_meta($post->ID, $key, true);
    if ($value != "") echo $value . " nautical miles";
?>

Hope this helps,
Dan

 

Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page @ Code Couch: http://www.codecouch.com/dan/

Code Couch Tech Snippets & Info: http://www.codecouch.com/
 

followtheboat (Programmer)
11 Dec 08 5:30
Hi Dan,

Thanks for your reply. I'll be trying this out this afternoon.
followtheboat (Programmer)
18 Dec 08 9:56
Sorry Dan, forgot to mention this worked well for me. Thanks.
BillyRayPreachersSon (Programmer)
18 Dec 08 12:03

No problem!

 

Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page @ Code Couch: http://www.codecouch.com/dan/

Code Couch Tech Snippets & Info: http://www.codecouch.com/
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close