0

正如您在http://www.mattmaclennan.co.uk/a2上看到的......当您将鼠标悬停在“新摩托车”上时,它具有数组编号,而不是所需的标签。此外,需要将类别分组到它们的 ID 中。以下是我尝试过的。

<?
$output = mysqli_query("SELECT * FROM bikes, bikeTypes WHERE bikes.model_id = bikeTypes.model_id");
$result = array();
while($row = mysqli_fetch_array($output))
  {
    $result[] = $row;
  }
//var_dump($result);
 foreach ($result as $key => $val) {
    echo "<li><a href='test.php?id=" . $val['model_id'] . "'>".$key.'</a><ul>';
    echo "<li><a href='details.php?id=" . $val['bike_id'] . "'>" . $val['bikeName'] . "</a></li>";
    echo '</ul>';   
    echo '</li>';
  }
?>

类别字段称为“模型”。谢谢你的帮助!

4

1 回答 1

1

那是因为您显示的是 $key,而不是 $value。

<?
$output = mysqli_query("SELECT * FROM bikes, bikeTypes WHERE bikes.model_id = bikeTypes.model_id");
while($row = mysqli_fetch_array($output))
  {
     echo "<li><a href='test.php?id=" . $row['model_id'] . "'>".$row['???'].'</a><ul>';
     echo "<li><a href='details.php?id=" . $row['bike_id'] . "'>" . $row['bikeName'] . "</a></li>";
     echo '</ul>';   
     echo '</li>';
  }
?>
于 2012-11-01T20:15:19.757 回答