Whenever you write the same chunk of code more than twice, it's a pretty fair guess to suspect that you're doing something better left to a machine to do 🙂
function subcategories($cat_id, &$results)
{
$query = 'select cat_id, cat_father_id, category from '.$prefix.'store_category where cat_id='.$cat_id;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
// Shove them onto the beginning of the array so
// that they end up in reverse order.
array_unshift($results, $row);
}
print ("<table border='0' width='100%' cellspacing='0' cellpadding='2'><tr><td width='100%'><a href='index.php'>$la_search_home</a>");
$results = array();
while($cat_id!=0)
{
subcategories($cat_id, $results);
$cat_id = $results[0]['cat_father_id'];
}
foreach($results as $result)
{
print "> <a href='index.php?cat_id=".$result['cat_id']."&catname=".urlencode($result['category'])."'>".$result['category']."</a>";
}
print "</td></tr></table>";
That looks about right, but it's completely untested. The basic idea is there, though.