Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    125
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Help getting started with a PHP app...

    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!!!

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    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

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    125
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PappaJohn View Post
    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...

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    125
    Thanks
    30
    Thanked 0 Times in 0 Posts
    For anyone that's interested, this is exactly what I needed. Hope it can help others!:

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


  • #5
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    You may want to consider a better designed database structure.

    Code:
    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.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #6
    Regular Coder
    Join Date
    Sep 2007
    Posts
    125
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by syosoft View Post
    You may want to consider a better designed database structure.

    Code:
    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!...

  • #7
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    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.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • Users who have thanked syosoft for this post:

    ShootingBlanks (05-17-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •