...

View Full Version : Help getting started with a PHP app...



ShootingBlanks
05-14-2008, 11:42 PM
Hello. I need some help getting started with a PHP app. Even if specifics aren't provided, just a general "how to" of what I should google for or look into would be great (although specifics would be even better! ;))...

I'm going to have three MySQL tables:

One will hold "categories"
One will hold "subcategories"
One will be a lookup table to relate the two based on their unique ids


I can make that part up no problem, so I don't need help on that...

I want to have either an HTML combo box or an HTML drop-down menu that lists all the categories. I can do that too. Here's the part where I'd have trouble...

...After a user selects one of the categories, I'd want ANOTHER combo box/drop-down menu to appear with that selected category's list of associated sub-categories to choose from. So, basically the page would update as soon as a category was selected.

Is this possible? Is the "PHP Forum" even the right place to be asking this question??? (I'm making the whole overall app in PHP - this is just a part of it)...

Thanks so much for any help that can be offered!!!

PappaJohn
05-14-2008, 11:46 PM
You are going to have to use javascript and employ AJAX techniques to do what you want without a page refresh before the subcategories list is displayed.

Google AJAX

ShootingBlanks
05-14-2008, 11:48 PM
Google AJAX

Cool - I'll get started with that. I have Dreamweaver CS3 and I know it has some sort of AJAX features, although I haven't messed around with any of them...

ShootingBlanks
05-15-2008, 07:09 PM
For anyone that's interested, this is exactly what I needed. Hope it can help others!:

http://www.developer.com/services/article.php/3575081

:thumbsup:

syosoft
05-16-2008, 08:48 AM
You may want to consider a better designed database structure.



category table design
--------------------------------------------------------------------
category_id | parent_category_id | name | description | image | order
--------------------------------------------------------------------


This would handle your three tables in one. The only "kicker" being that you couldn't reuse subcategories in other categories, thou I can't see any reason why you'd want to do that in the first place as it would completely undermine having a unique category_id/subcategory_id with which to associate other things (images, etc) in the first place.

Just a suggestion.

ShootingBlanks
05-16-2008, 03:40 PM
You may want to consider a better designed database structure.



category table design
--------------------------------------------------------------------
category_id | parent_category_id | name | description | image | order
--------------------------------------------------------------------


This would handle your three tables in one. The only "kicker" being that you couldn't reuse subcategories in other categories, thou I can't see any reason why you'd want to do that in the first place as it would completely undermine having a unique category_id/subcategory_id with which to associate other things (images, etc) in the first place.

Just a suggestion.

I'd much rather have a cleaner database, so I appreciate the suggestion. Can you elaborate more. I see you have "description", "image", and "order" columns - what would those be for. I really only need the category names, the sub-category names, and how they belong to each other...

You are correct in saying that the subcategories will not be re-used, but the NAMES of them will (in some cases). Like, there is more than one category that has a "General" sub-category, but I would want different entries for each one ("Category1--->General", "Category2--->General", etc)...

Thanks!...

syosoft
05-17-2008, 08:18 AM
Those "extra" columns are really just there to show the scope of the database table - or what it could be. If all you need is a category id, parent category id, and name, thats fine.

The reuse of names is not a big deal (unless you've got a url scheme that requires unique names...i.e. /category/jeans.html maps to category_id 6) at all - This is the point of having auto incrementing columns.

Not sure what I need to elaborate on. You really don't need to change your queries all that much to get at the same information. You'd just be querying the database for all categories with a parent id of x (0 if its top level). Or you could pull all categories and play around with building the appropriate array structure with recursion.

This was only a suggestion because i'm guessing your sub-category table was/is the same as your category table (apparently just id and name) and then you were linking them with the 3rd table... seems sloppy when the same can be done with a single 3 column db table is all. You'll just have to write slightly different queries.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum