if / elseif syntax
I'm having some trouble with the following code, more than likely a n00b error so apologies in advance if the answer is obvious. The if/elseif/if wor开发者_StackOverflowks without the content but not with the test statements. Is there some subtlety of syntax i'm missing.
<?php
if (stripos($_SERVER['REQUEST_URI'],'/workshops/') !== false) {echo ''
}; elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true))
{ echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="'.$ticketlink.'" title="Buy tickets" target="_blank">Buy Tickets</a>';}
else { echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>' ;}
?>
You have a ;
after your if
and missing a ;
after the first echo
<?php
if (stripos($_SERVER['REQUEST_URI'],'/workshops/') !== false) {
echo '';
}
elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true)) {
echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="'.$ticketlink.'" title="Buy tickets" target="_blank">Buy Tickets</a>';
}
else {
echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>';
}
?>
You just have a small syntax mistake. And how is this code formatting readable for you? Use something like this instead:
<?php
if (stripos($_SERVER['REQUEST_URI'],'/workshops/') !== false) {
echo '';
} elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true)) {
echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="' . $ticketlink . '" title="Buy tickets" target="_blank">Buy Tickets</a>';
} else {
echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>';
}
?>
The error is this: echo '' };
, should be echo ''; }
.
Lose the semi-colon before "elseif";
<?php
if(stripos($_SERVER['REQUEST_URI'],'/workshops/') !== false)
{
echo '';
}
elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true))
{
echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="'.$ticketlink.'" title="Buy tickets" target="_blank">Buy Tickets</a>';
}
else
{
echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>';
}
?>
Your code is really messy. Try cleaning it up a little bit and most syntax errors will reveal themselves right away.
Here is your code with better formatting and dropped semicolon that was causing your problems:
<?php
if (stripos($_SERVER['REQUEST_URI'],'/workshops/') !== false)
{
echo ''
} elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true)) {
echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="'.$ticketlink.'" title="Buy tickets" target="_blank">Buy Tickets</a>';
} else {
echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>';
}
?>
精彩评论