Jump to content

display all entries in category


tjodalv

Recommended Posts

HelloI have app that has categories and subcategories and products. My app can have unlimited categories and subcategories and subcategories can go in unlimited deep.Structure of my table that holds categories and subcategories is:id - autonumber (category ID)parentID - number (holds the ID of parent categorie)name - txt (category name)Structure of table that holds productsid - autonumber (product ID)catID - number (category ID)name - txt (product name)Now if I have category Memory, and it's parent category Components. I want to, when is selected category Components, display all products that is in Component category and all products that is in child category.Tnx

Link to comment
Share on other sites

I share your pain...I had the same problem a while back and never solved it. I ended up useing a product that used xml nodes to build a "tree" it allowed me to navigate to the specific node I needed at a specific time.

Link to comment
Share on other sites

You will want to use a recursive function, or a function that calls itself. I'll leave it up to you to figure out how to do it in vb script:

function display_cats(catID){  var dbcon = Server.CreateObject("ADODB.Recordset");  //set up database object    dbcon.open("SELECT * FROM categories WHERE id=" + catID);  Response.write(dbcon.fields.item("name").value + ":<br>");  dbcon.close();  dbcon.open("SELECT * FROM products WHERE catID=" + catID);  while(!dbcon.eof)  {	Response.write(dbcon.fields.item("name").value + "<br>");	dbcon.movenext();  }  dbcon.close();  dbcon.open("SELECT id FROM categories WHERE parentID=" + catID);  while (!dbcon.eof)  {	display_cats(dbcon.fields.item("id").value);	dbcon.movenext();  }  dbcon.close();}display_cats(0); //start it off with whatever category you want to display

This function gets the category ID you want to display, displays information about that category from the database, then displays all of the products in the category, then displays all of the children in that category. Since it calls itself again to display the children, it will recurse as many times as needed to display all of the levels. You can add another parameter to the function to indent, and increase the indent parameter by one whenever you recurse the function.Ask if you have any questions on how this works.WTF, I'm trying to write this sentence on the top of my post without the spaces:I'll leave it up to you to figure out how to do it in V B S c r i p t, but this is how you do it in J a v a s c r i p t:and it keeps truncating the sentence to what you see up there. What gives? Is that some type of lame "security" thing?

Link to comment
Share on other sites

Is that some type of lame "security" thing?
I believe so. This version of IPB sperates "key" words like this: javascript - script - vbscriptThis verison also won't let you reply 2 times in a row...it adds it to the bottom of your last post.EDIT: ok it didn't seperate it this time...it has been happening everytime...except now hmmmm
Link to comment
Share on other sites

I guess I'm confused as to why typing "vbscript" is a security issue then.Apparently now it isn't. IPB is so advanced as to be able to determine when I am trying to be helpful, and only mess me up at that point.Why did it cut off the rest of my line though? That's a little irritating. I probably re-edited the same thing 3 times and kept hitting refresh and leaving and entering before I decided that maybe it was a "feature". No notificaton or anything, I need to have a word with those developers!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...