Code syntax for PHP in <a> tag

I have this line in my code:
[php]<a <? = ($id == 1) ? 'class="Current"' : 'href="sample.php?id=1"';?>>Tab 1[/php]

it returns a few tabs that when i click on a page loads up under the tag. But for some reason the tab title comes out as “> Tag 1” instead of “Tag 1”. For some reason the closing “>” bracket of the tag is being sent as text. So does anyone know the syntax of how i would write that line?

Here is the line in context.

[php]

<?php $id = isset($_GET['id']) ? $_GET['id'] : 1; ?>
>Tab 1 >Tab 2 >Tab 3 >Tab 4
Page 1
<?php include("../donate.php");?>
Page 2
Page 3
Page 4
[/php]

I’m not sure you can use <?= with If…

try to put
<a <?php ($id == 1) ? echo 'class="Current"' : echo 'href="sample.php?id=1"';?>>Tab 1

I still get the mucked up output plus when I open the statement with <?php it breaks the code but when i open the statement with <? it runs through the code.

This works but I still have the problem with the tab displaying as "> Tab1>
[php]<a <? =($id == 1)? echo 'class="Current"' : echo 'href="sample.php?id=1"';?>>Patches[/php]

This just shows a blank page
[php]<a [b]<?php[/b] =($id == 1)? echo 'class="Current"' : echo 'href="sample.php?id=1"';?>>Patches[/php]

This page has the complete source for download:
http://www.php-development.ru/javascripts/tab-view.php

Maybe it is a problem with my parser I am using VC9 PHP 5.3.6 with Apache 2.X (WAMP) so could someone test it and tell me if that code runs OK on their machine?

I think this code must works,

in your example you write
<a <?php =($id == 1)? echo 'class="Current"' : echo 'href="sample.php?id=1"';?>>Patches

You can write <?php = you must write without =.
<a <?php ($id == 1)? echo 'class="Current"' : echo 'href="sample.php?id=1"';?>

But if don’t works try with if… else
[php]

<a

<?php if ($id == 1) { echo 'class="Current"'; }else{ echo 'href="sample.php?id=1"'; } ?>

Tab 1[/php]

Thanks for your help. I never got it to work on my local WAMP.

For some strange assed reason it won’t parse the code properly. But I uploaded to my live site and modified the code there and it all seems to work properly.

Got the tab working with some flat file database info in it.
http://ephestion.mygamesonline.org/?ir=./tab/sample

If you have time to visit please tell me if it worked in your browser, because I had probs with that issue too.

Sponsor our Newsletter | Privacy Policy | Terms of Service