Can't get code to echo

Folks,

Cast your eyes over this one for me please…

I have a swap image behaviour using images pulled from a database thus…


<img id="main" src="<? echo $pic1 ?>"> 
<a href="#" onclick="main.src='<? echo $pic2 ?>';"> 2 </a>

All great works fine. But I need to echo this statment based on previous if querys


echo '<a href="#" onclick="main.src='.$pic2.';">2</a>';

And I can’t get the ■■■■ thing to work. Any ideas folks?

Thanks in advance