<?php

$sql = "SELECT * FROM lang WHERE active=1 AND main=1";

$result = mysql_query($sql);

while ($myrow=mysql_fetch_array($result)) {

$langid=$myrow['id'];

$language=$myrow['language'];

$dir=$myrow['dir'];

if ($pages=='index.php') { 

$pageurl="";

}

?>

<a href="/<?php echo $pageurl ?>"><img src="<?php echo $sitepath ?>images/<?php echo $dir ?>.png" alt="lang"></a>

<?php } ?>

<?php

$sql = "SELECT * FROM lang WHERE active=1 AND main=0 ORDER BY id";

$result = mysql_query($sql);

while ($myrow=mysql_fetch_array($result)) {

$langid=$myrow['id'];

$language=$myrow['language'];

$dir=$myrow['dir'];

?>

<a href="/<?php echo $dir ?>/<?php echo $pageurl ?>"><img src="<?php echo $sitepath ?>images/<?php echo $dir ?>.png" alt="lang"></a>

<?php } ?>