<?php
function mymenu_s() {
global $prefix, $db, $module_name;
	$pagetitle = "Пример работы с select";
		head();
	OpenTable();
	echo "<center><font class=\"title\">Пример работы с select</font></center><br />";
	CloseTable();
        OpenTable();

if ($_POST['kuda'])
{
	$idk = intval($_POST['kuda']);
Header("Location: index.php?name=News&op=article&sid=$idk");
}

	$ok = intval($_GET['num']);

if ($ok=='2') {
$expl='size="10"';

}
else {
$expl='style="width:200px"';
}
$fkat='';
$result = $db->sql_query("SELECT f.catid, f.sid, f.title, s.title, s.catid FROM ".$prefix."_stories AS f LEFT JOIN ".$prefix."_stories_cat AS s on (f.catid=s.catid)");
while(list($fcatid, $sid, $titlem, $titlec, $scatid) = $db->sql_fetchrow($result)) {
if ($scatid=='') {
$titlec="Нет категории";
$scatid='0';
}
$mass1[$scatid] = array($scatid, $titlec);
$mass2[$scatid][$sid] = array($sid, $titlem, $fcatid);
}
foreach ($mass1 as $key1 => $val1) {
$fkat .="<option value='$val1[0]'>$val1[1]</option>";
$prep .="'$val1[0]':{";
$prep2 ='';		
foreach ($mass2[$key1] as $key2 => $val2) {
$prep2 .="'$val2[0]':'$val2[1]',";
}
$prep .=substr($prep2, 0, -1);
$prep .="}, ";
}
$fkat2 =substr($prep, 0, -2);
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">";
echo "<script type=\"text/javascript\" src=\"linkedselect.js\"></script>";
echo "<form name=\"post\" action=\"\" method=\"post\">";
echo "<tr><td>Выберите категорию:</td> <td><select $expl id=\"List1\"><br>";
echo "$fkat";
echo "</select></td></tr>";
echo "<tr><td>Выберите статью:</td> <td><select name=\"kuda\" $expl id=\"List2\"></select></td></tr>";
echo "<tr><td><input type=\"submit\" value=\"Перейти к статье\"></td></tr></form>";
$cont .="<script type=\"text/javascript\">"
."var syncList1 = new syncList;"
."syncList1.dataList = {";
$cont .=$fkat2;
$cont .="};";
$cont .="syncList1.sync(\"List1\",\"List2\")</script>";
echo "$cont<br><br><br></table><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" class=\"bodyline\"><tr><td class=\"bgcolor1\"><center><a href=\"index.php?name=test\">Первый вариант</a> | <a href=\"index.php?name=test&num=2\">Второй вариант</a></center><br /></td></tr></table>";
CloseTable();
foot();

}

switch ($op) {
	default:
    mymenu_s();
    break;
}

?>