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:
$dbh mysql_connect(hostnameusernamepassword)
    or die(
"Unable to connect to MySQL");
mysql_select_db ("morenotravel"$dbh);
$query sprintf("SELECT 
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='

$result mysql_query($query);

if (!
$result) {

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

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



while (
$row mysql_fetch_assoc($result)) {

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!