0

This is my first project digging into PHP and mySQL databases, and it's been a steep learning curve so far. I'm near the end of a Wordpress project and could use some help on if...else statements, which have been stumping me for a while. It uses custom fields.

Essentially I need the below flow, where "c01-sp-a" is a one word text variable and "c01-sp-v" is a number. I put variables in [] to clarify:

if ([c01-sp-a] = null)
    [text of c01-sp-v]
else
    <a href="http://www.example.com/[text of c01-sp-a]" title="[text of c01-sp-a]" target="_blank">[text of c01-sp-v]</a>

I'd have to repeat this a few times, but I'd imagine having a good example for me would get me going.

Thanks!

2
  • You want to echo something or what, it's not clarified what's the expected and what's the unusual result Commented Aug 4, 2013 at 17:18
  • You need to add curly braces where appropriate Commented Aug 4, 2013 at 17:22

2 Answers 2

4

You mean like this?

if ($c01_sp_a == null) {
    echo $c01_sp_v;
} else {
    echo '<a href="http://www.example.com/'.$c01_sp_a'." title="'.$c01_sp_a.'" target="_blank">'.$c01_sp_v'.</a>';
}
Sign up to request clarification or add additional context in comments.

Comments

1

your variable can not contain '-' , you have to change your variable names ( i assume that variables are c01_sp_a and $c01_sp_v

if ($c01_sp_a == null)
    echo $c01_sp_a;
else
    <a href="http://www.example.com/<?php echo $c01_sp_a;?>" title="<?php echo $c01_sp_a; ?>" target="_blank"><?php echo $c01_sp_v;?></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.