I'm having trouble wrapping my brain around this so hopefully someone can help get me on the right track. Here's what I'm trying to do. I have a table of tour packages and a table of categories. I then have a third table to link the two together. They look like this:




Now for every tour package, there will be a tab on the website that will say "similar trips". This will (1) identify the category and/or categories associated with the selected package and (2)list other packages that are also assigned to that same category/categories.

To start, I was able to get the step (1) above with the following code:

PHP Code:
<?php
$package_id
=$_GET['package_id'];
require_once(
'connectvars.php');
$dbh mysql_connect(hostnameusernamepassword)
    or die(
"Unable to connect to MySQL");
mysql_select_db ("morenotravel"$dbh);
$query sprintf("SELECT 
categorypackagelink.package_id,
categorypackagelink.category_id,
packages.package_name,
packages.package_id,
category.category_id,
category.category
FROM category
INNER JOIN categorypackagelink ON categorypackagelink.category_id = category.category_id
INNER JOIN packages ON packages.package_id = categorypackagelink.package_id
WHERE packages.package_id='
$package_id'");


$result mysql_query($query);

if (!
$result) {

    
$message  'Invalid query: ' mysql_error() . "\n";

    
$message .= 'Whole query: ' $query;

    die(
$message);

}


while (
$row mysql_fetch_assoc($result)) {

echo 
$row['category'];
}
?>
This displays the category which is associated with that package just perfectly. My problem then comes with step (2) which is to list out other packages with that same category. I actually have no idea how to incorporate a second query based on the first.

Anybody able to give me a little bit of direction? If any other info is needed, just let me know. Thank you in advance!