Jump to content

Recommended Posts

Posted

To those more PHP inclined,

 

I am running osCommerce with a tabbed navigation contribution. If you go to my website and click on the Knives tab you will see sub categories. Check any other tab and there is nothing.

 

I did a search on the forums for osc and the maker hasn't done anything in some time. I am wondering if anyone can look at the code , it is one page and see if I am missing something in getting it to work.

 

Here are the parts pertaining to the sub-categories;

 

><?php
function show_subcategories($counter) 
{
global $fooa, $subcategories_string, $id, $HTTP_GET_VARS;
$cPath_new = 'cPath=' . $fooa[$counter]['path'];

$subcategories_string .= '<a href="';
$subcategories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);
$subcategories_string .= '"  class="headerNavigation">';

// display category name
$subcategories_string .= $fooa[$counter]['name'];

$subcategories_string .= '</a> ';

if ($fooa[$counter]['next_id']) {
 $subcategories_string .= '| ';
 show_subcategories($fooa[$counter]['next_id']);
}else{
 $subcategories_string .= ' ';
}

}
?>

 

And

 

><!-- subcategories //-->
<table border="0" cellspacing="0" cellpadding="4" WIDTH="100%">
<tr class="headerNavigation"><td ALIGN="CENTER" class="headerNavigation">
<?php
if ($cPath) {
 $subcategories_string = '';
 $new_path = '';
 $id = split('_', $cPath);
 reset($id);
 while (list($key, $value) = each($id)) {
	 unset($prev_id);
	 unset($first_id);
	 $subcategories_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 = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");
	 $subcategory_check = tep_db_num_rows($subcategories_query);
	 if ($subcategory_check > 0) {
   $new_path .= $value;
   while ($row = tep_db_fetch_array($subcategories_query)) {
  	 $fooa[$row['categories_id']] = array(
     'name' => $row['categories_name'],
     'parent' => $row['parent_id'],
     'level' => $key+1,
     'path' => $new_path . '_' . $row['categories_id'],
     'next_id' => false
  	 );
  	 if (isset($prev_id)) {
     $fooa[$prev_id]['next_id'] = $row['categories_id'];
  	 }

  	 $prev_id = $row['categories_id'];
  	 
  	 if (!isset($first_id)) {
     $first_id = $row['categories_id'];
  	 }

  	 $last_id = $row['categories_id'];
   }
   $fooa[$last_id]['next_id'] = $fooa[$value]['next_id'];
   $fooa[$value]['next_id'] = $first_id;
   $new_path .= '_';
	 } else {
   break;
	 }
 }
}

if ($id[0][0] != ''){
 show_subcategories($id[0][0]); 
 echo $subcategories_string;
}else{
 echo " ";
}

?>
</td>
</tr>
</table>
         
<!-- subcategories_eof //-->

 

If needed I can provide all of the code should anyone need to see the whole thing in context.

 

I don't know PHP well enough to debug this.

 

Any help would be appreciated.

Posted

Well, I've never used or really looked at osCommerce, so forgive any dumb questions I ask. :)

 

How is the category and sub category listings stored? It's there a table somewhere?

 

I ask because of the way the links appear to work. From first glance, the main headings are single numbers (like 'Knives' is 1, 'Camping' is 19), and the sub categories are two sets of numbers (like 'dagger' is 1_15), with it's main cetegory being the first number.

 

But then if I go to 2 directly (just typing h**p://www.knifeandblade.com/shop/index.php/cPath/2 into the address bar), I get to butterfly knives, which is the same as going to 1_2 (the subcategory). Something seems odd about that, but it may just be osCommerce. Anyone know for sure?

 

I'm looking at the page output and comparing that to the source... will try to post something in a few minutes.

Posted

Ok, I see that there is a table. :)

 

I clicked on knife and then on camping to compare the source of the pages that are being output.

 

Basically, knife gives you a listing such as...

><a href="http://www.knifeandblade.com/shop/index.php/cPath/"  class="headerNavigation"></a> 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_18"  class="headerNavigation">Accessories</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_13"  class="headerNavigation">Boot</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_2"  class="headerNavigation">Butterfly</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_9"  class="headerNavigation">Collector</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_7"  class="headerNavigation">Combat</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_15"  class="headerNavigation">Dagger</a> | 
<a href="http://www.knifeandblade.com/shop/index.php/cPath/1_10"  class="headerNavigation">Diving</a> |

 

Camping gives you....

><a href="http://www.knifeandblade.com/shop/index.php/cPath/"  class="headerNavigation"></a>

That means it's calling the show_subcategories method at least. But it's probably passing in incorrect values.

Because the knives section works, I'm wary to say there's anything wrong with the code itself. I would look into your database table to start with and make sure your categories_id and parent_id values are correct for anything except the knives.

Posted

vendlus,

 

Thanks for the info, I will look into it. I know there are about a dozen others with the same issue though. I will see what the tables are showing.

 

Thanks,

Posted
vendlus,

 

Thanks for the info, I will look into it. I know there are about a dozen others with the same issue though. I will see what the tables are showing.

 

Thanks,

Ah, so it's a widespread issue. Dang. If I had time, I'd load up a copy of it in a test folder somewhere, but I don't really. :) Sorry. If anything profound comes to me, I'll throw it your way.

 

Just a thought. (well, two)

The one place I could see it screwing up the easiest is with the counter somewhere. Two possibilities (since you are working with it, you can better say if either of these are possible with the way they have it set up)....

One is that it wants all of the main categories at the front of the list. While it shouldn't matter at all, maybe it's got a quirk somewhere.

 

The other one is more possible, though it shouldn't be a problem at all if I'm reading their database query correctly. They may want all of the subcategories for a given category directly behind it in number. Like the ones after knives are 2-whatever. Maybe for camping (which is 19) it needs 20 through whatever. That would be a total counter screwup on their part, but that's just a random thought off the top of my head.

Posted

So I am looking at the table for categories and it looks like the number was given to each category/sub as they were uploaded to the database. So for example pocket tools was given a number of 30 and swords was given a number of 33. I have 2 subs under pocket tools there are 2 subs and they have numbers 31 and 32.

 

I am wondering if that is what may be happening.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...