У меня есть этот скрипт, чтобы получить дерево категорий из базы данных и показать его в виде HTML SELECT
function CategoryTree(&$output=null, $cat_parent_id=0, $indent=null){
$con = new PDO("mysql:host=localhost;dbname=test-2", 'root', '');
try {
// prepare select query
$query = "SELECT cat_id, cat_name FROM category WHERE cat_parent_id=:parentid";
$stmt = $con->prepare($query);
// this is the first question mark
$stmt->bindParam(2, $id);
// execute our query
$stmt->execute(array( 'parentid' => $cat_parent_id));
// show the categories one by one
while($c = $stmt->fetch(PDO::FETCH_ASSOC)){
$output .= '<option value=' . $c['cat_id'] . '>' . $indent . $c['cat_name'] . "</option>\n";
if($c['cat_id'] != $cat_parent_id){
CategoryTree($output, $c['cat_id'], $indent . " ");
}
}
// return the list of categories
return $output;
}
// show error
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
}
и HTML:
<td><select name="category" id="category" required="">
<option value='0'>Select the category</option>
<?php
echo CategoryTree();
?>
</select>
</td>
Я хотел бы, чтобы когда cat_parent_id =0 в html select, cat_name не кликабелен, просто выделите его жирным шрифтом.Хотя, если cat_parent_id> 0 остаются доступными для выбора в HTML выберите.
Как я могу это сделать?Спасибо