Как мне его вставить в <inpute .....> чтобы я мог передать в SQL данные из этой функции.
Функция рисования дерева рекурсивная.
Код
function ShowTree($first = 0, $node_id = "", $index = 0) {
if($first == 0){
echo"<select name=\"Category_id\" onchange=\"MM_jumpMenu('parent',this,0)\">";
$first = 1;
}
if (strlen(trim($node_id)) == 0) $condition = "Category_id is NULL";
else $condition = "Category_id = {$node_id}";
$prefix = "";
for($i = 0; $i < $index; $i++) $prefix = $prefix." ";
$sqlstat = "SELECT id, Category FROM Category WHERE {$condition}";
$result = mssql_query($sqlstat);
while($row = mssql_fetch_array($result)) {
$Element_id = $row["id"];
$ElementValue = $row["Category"];
$this_sql = "SELECT cnt = count(*) FROM Category WHERE Category_id = {$Element_id}";
$this_res = mssql_query($this_sql);
$this_cnt = mssql_result($this_res, 0, "cnt");
$ans_sql = "SELECT cnt = count(*) FROM Answer WHERE Category_id = {$Element_id}";
$ans_res = mssql_query($ans_sql);
$ans_cnt = mssql_result($ans_res, 0, "cnt");
if ($this_cnt > 0) {
echo "<option value =".$row["id"]." >{$prefix}{$ElementValue}</option>";
ShowTree($first, $Element_id, $index + 1);
} else {
if ($ans_cnt > 0) {
echo "<option value =".$row["id"]." >{$prefix}{$ElementValue}</option>";
} else echo "<option value =".$row["id"]." >{$prefix} - {$ElementValue}</option>";
}
}
return $Category_id;
}
if($first == 0){
echo"<select name=\"Category_id\" onchange=\"MM_jumpMenu('parent',this,0)\">";
$first = 1;
}
if (strlen(trim($node_id)) == 0) $condition = "Category_id is NULL";
else $condition = "Category_id = {$node_id}";
$prefix = "";
for($i = 0; $i < $index; $i++) $prefix = $prefix." ";
$sqlstat = "SELECT id, Category FROM Category WHERE {$condition}";
$result = mssql_query($sqlstat);
while($row = mssql_fetch_array($result)) {
$Element_id = $row["id"];
$ElementValue = $row["Category"];
$this_sql = "SELECT cnt = count(*) FROM Category WHERE Category_id = {$Element_id}";
$this_res = mssql_query($this_sql);
$this_cnt = mssql_result($this_res, 0, "cnt");
$ans_sql = "SELECT cnt = count(*) FROM Answer WHERE Category_id = {$Element_id}";
$ans_res = mssql_query($ans_sql);
$ans_cnt = mssql_result($ans_res, 0, "cnt");
if ($this_cnt > 0) {
echo "<option value =".$row["id"]." >{$prefix}{$ElementValue}</option>";
ShowTree($first, $Element_id, $index + 1);
} else {
if ($ans_cnt > 0) {
echo "<option value =".$row["id"]." >{$prefix}{$ElementValue}</option>";
} else echo "<option value =".$row["id"]." >{$prefix} - {$ElementValue}</option>";
}
}
return $Category_id;
}
Из кода видно, что эта фунция рисует дерево в JampMenu. Так вот. Я её не знаю как запустить в тегаф
<form action ......>
<input .....>
<input .....>
Вот как её запустить, чтобы база поняла какую я выбрал категорию?? ( ShowTree(); )
<inpute type = "submit" ....>
</form>