I have this script that loops to make a category tree. But I want it to display specific categories that a user picks like in the example below. On a side note the script loops in-order to build the url link to the category.
I guess what I'm trying to say is that I just want to know how to display specific categories and their full url?
Here is the example.
Found In Category: Books & Authors, Html, Web design
Here is my PHP script.
function make_list ($parent = 0, $parent_url = '') {
global $link;
echo '<ol>';
foreach ($parent as $id => $cat) {
$url = $parent_url . $cat['url'];
echo '<li><a href="' . $url . '" title="' . $cat['category'] . ' Category Link">' . $cat['category'] . '</a>';
if (isset($link[$id])) {
make_list($link[$id], $url); // $url adds url value to sub categories
}
echo '</li>';
}
echo '</ol>';
}
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT * FROM categories ORDER BY parent_id, category ASC");
if (!$dbc) {
print mysqli_error();
}
$link = array();
while (list($id, $parent_id, $category, $url) = mysqli_fetch_array($dbc)) {
$link[$parent_id][$id] = array('category' => $category, 'url' => $url);
}
make_list($link[0]);