2010-08-17 125 views
0

我需要更正使用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]); 

回答

0

貌似http://localhost/index.php后,从第四栏即将在categories表的一切。

看不到多个级别的类别的任何级联,都似乎只是从当前类别。

在下面的循环中,它看起来像你必须获取父id的链接的'url'字段,无论如何,并追加新的$ url而不是仅仅使用数据库中的内容。

while (list($id, $parent_id, $category, $url) = mysqli_fetch_array($dbc, MYSQLI_NUM)) { 
    $link[$parent_id][$id] = array('category' => $category, 'url' => $url); 
} 
+0

我该怎么做呢?自从我编写PHP以来,这已经有一段时间了 – HiThere 2010-08-17 02:53:01