Jump to content

Archived

This topic is now archived and is closed to further replies.

spoot

help w/trying to simplify categories.php

Recommended Posts

Hi -

 

I just started working with oscommerce, and love what I see. I have a few questions, starting with this one:

 

I'm trying to change the way categories display in column_left.php.

 

My shop will have four parent categories, each of which will may or may not have a few child categories.

 

The parent categories are selected from static mouseover links in the header.

 

When a parent category is selected, I want only that category and its children to appear in the left column.

 

I was able to edit categories.php to get the parent and child categories to look the way I wanted them to look; but I haven't been able to sort through categories.php to have only the selected parent category appear. The other parents are always hanging around.

 

I thought I'd try to write my own simple version of categories.php, but it's giving me nothing. (Literally - no output at all, even when I put something like "echo "blah blah blah"; at the top of the script.) I assume I'm either making a simple mistake, or missing some necessary element that's in the original category.php. Any help is greatly appreciated.

 

Here's what I've got for my-categories.php:

 

<?php

// test intended to frustrate me, since it doesn't output anything

echo "cPath is $cPath";

// first check to see if this is a parent or a child
// (any child should be in the format x_y; parent should
// just be plain old x)

if preg_match("_",$cPath) {
 leftNavBody($cPath);
}
else {
 leftNavHead($cPath);
}

// make the header
function leftNavHead($cPath) {
 $category_query = tep_db_query("select * from categories_description where categories_id = $cPath and language_id = '1'");
 $category = tep_db_fetch_array($category_query);
$cat_name = $category['categories_name'];

echo "<tr><td class=\"left-nav-head\">$cat_name</td></tr>";
}

// make subheads w/links - but add the header at the top!
function leftNavBody($cPath) {
 // separate the first and last numbers in cPath - they're
// the parent and child categories

$family = explode("_",$cPath);
$parent = $family[0];
$child = $family[1];

// make the header
leftNavHead($parent);

 $category_query = tep_db_query("select * from categories_description where categories_id = $child and language_id = '1'");
 $category = tep_db_fetch_array($category_query);
$cat_name = $category['categories_name'];

echo "<tr><td class=\"left-nav-off\" onmouseover=\"this.className='left-nav-on'\" onmouseout=\"this.className='left-nav-off'\"><a href=\"#\" class=\"nav\">$cat_name</a></td></tr>";
 }

?>

 

This isn't complete at all - the child categories won't have a header at this point - but I don't want to go too much further without having some output to look at. Any pointers? I expect (and hope) this will be a forehead-slapper...

 

Thanks in advance for any help -

 

Michael

Share this post


Link to post
Share on other sites

I was trying much too hard. All I needed to do was change the mysql query, from:

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

 

to:

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '$cPath' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

 

Replacing c.parent_id = '0' with c.categories_id = '$cPath'.

Share this post


Link to post
Share on other sites

×