tags:

views:

28

answers:

1

I need to correct the way my links are displayed using PHP for some reason my links sub categories are displayed in the following format below.

http://localhost/index.php&sub=sub1
http://localhost/index.php&sub3=sub3

When they should be displayed in the following format.

http://localhost/index.php?cat=2&sub=sub1
http://localhost/index.php?cat=2&sub=sub1&sub2=sub2&sub3=sub3

Can someone help me correct this problem?

Here is the PHP code.

function make_list ($parent = 0, $parent_url = 'http://localhost/index.php') {
    global $link;
    echo '<ol>';

    foreach ($parent as $id => $cat) {
        $url = $parent_url . $cat['url'];
        // Display the item:
        echo '<li><a href="' . $url . '" title="' . $cat['category'] . ' Category Link">' . $cat['category'] . '</a>';          

        if (isset($link[$id])) {
            make_list($link[$id]);  
        }               
        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, MYSQLI_NUM)) {
    $link[$parent_id][$id] =  array('category' => $category, 'url' => $url);
}
make_list($link[0]);
A: 

Looks like everything after http://localhost/index.php is coming from the fourth column in the categories table.

Can't see any concatenation of multiple levels of categories, all seems to be just from the current category.

Inside the below loop, it looks like you'll have to fetch the 'url' field of the parent id's link, whereever that is, and append the new $url to it instead of just using what's in the database.

while (list($id, $parent_id, $category, $url) = mysqli_fetch_array($dbc, MYSQLI_NUM)) {
    $link[$parent_id][$id] =  array('category' => $category, 'url' => $url);
}
thomasrutter
How would I go about doing that? its been a while since I coded PHP.
HiThere