I think you can accomplish what you are trying with use of the PHP Super-Global array(), $_GET
These are values that are passed in the query string, whose values can be easily converted to variables, validated, and used in your scripts.
For example, you may have links on page one:
<?php
// connect and query DB here...
?>
<ul>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<li><a href="page2.php?cat=' . $row['cat_id'] . '">' . htmlspecialchars( $row['cat_name'] ) . '</a></li>' . "\n";
}
?>
</ul>
Then, on page two, you could check to see if there is a GET value set for "cat" like:
<?php
$cat = 1; // create default
if(isset($_GET['cat']) && ctype_digit($_GET['cat']) )
{
$cat = (int)$_GET['cat'];
}
// etc...
?>
And you can then safely use your $cat variable in your script to determine the appropriate SUB-categories, etc..