hi everyone,
I have a function listing hierarchical categories I am using it in an update form in admin panel,
and have to copy and rename each time when need to use in another page.
I want to know how to use it in multiple pages and in li or option without copying it again and again
here is the function
$stmt = $conn->prepare("SELECT cat_id, cat_name, seo_url FROM categories WHERE parent_id = ?");
function list_categories($stmt, $parent_id = 0){
$stmt->reset();
$stmt->bind_param('i', $parent_id);
$stmt->execute();
$stmt->bind_result($cat_id, $cat_name, $seo_url);
$cats = array();
while($stmt->fetch()) $cats[] = array('cat_id' => $cat_id, 'cat_name' => $cat_name, 'seo_url' => $seo_url);
foreach($cats as $row) { //use rows instead cats
echo'<ul>';
echo'<li><a href="'.htmlspecialchars($row['cat_id']).'-'.htmlspecialchars($row['seo_url']).'">'.htmlspecialchars($row['cat_name']).'</a>';
list_categories($stmt, htmlspecialchars($row['cat_id']));
echo'</li>';
echo'</ul>';
}
}