well u can try this
first define the function as
<?
function print_table(){
global $img_clicked;
if(isset($img_clicked)){
if($img_clicked =='yes'){
print("second table");
}else{
print("first table");
}
}
}
?>
then put <?php print_table() ?> where u want the tables to appear
and put the img to have
<form name='img_clicked' method='post' action='<?php print $PHP_SELF ?>' >
<input type='hidden' name='img_clicked' value='yes'>
<a href='#'><img src='' onClick="javascript:this.formname.submit();" border='0'></a>
</form>
when this form is submitted u should switch to second table and u r done 🙂