PHP链接显示问题

时间:2010-08-17 02:43:15

标签: php

由于某些原因,我需要更正使用PHP显示链接的方式我的链接子类别在下面的格式中显示。

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

何时应以下列格式显示。

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

有人可以帮我纠正这个问题吗?

这是PHP代码。

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]);

1 个答案:

答案 0 :(得分:0)

看起来http://localhost/index.php之后的所有内容都来自categories表格中的第四列。

无法看到多个类别级别的任何串联,似乎只是来自当前类别。

在下面的循环中,看起来你必须获取父id的链接的'url'字段,无论是什么,并将新的$ url附加到它而不是仅使用数据库中的内容。 / p>

while (list($id, $parent_id, $category, $url) = mysqli_fetch_array($dbc, MYSQLI_NUM)) {
    $link[$parent_id][$id] =  array('category' => $category, 'url' => $url);
}
相关问题