0

As you can see on http://www.mattmaclennan.co.uk/a2 ... when you hover over "New Motorcycles", it has the array numbers, and not the labels as required. Also, the categories need to be grouped into their IDs. Below is what I have tried.

<?
$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>';
  }
?>

The category field is called 'model'. Thanks for any help!

1 Answer 1

1

Thats because you're display the $key, instead of the $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>';
  }
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Hey there! thanks for the input. it has added the names successfully, but need it grouped now. I tried adding "GROUP BY bikes.model_id", but that didn't work. Any ideas?
What do you mean? How are you trying to display the information? GROUP BY may not be what you're looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.