PHP problem - Help needed

by rrahman 8 replies
Hello programmers,

I am developing a web page. now my problem is...

I am working with relation database. I have a category and subcategory option and so in my form there are 2 list one category menu list and subcategory menu list.

So I want to know that if I select a category from a list immediately show all subcategory of that selected category from database.

Waiting for solution.
#programming #needed #php #problem
Avatar of Unregistered
  • Profile picture of the author SteveSRS
    If you have the proper relations set and your db is relational yes it will...
    however you're a bit vague.. you might wanna include some more info like which database you are working with.
    {{ DiscussionBoard.errors[7724565].message }}
    • Profile picture of the author viescripts
      SteveSRS is right, your problem is not very clear.

      Do you want to know what DB structure to use for categories/subcategories and the way of relations between them,
      or do you want a solution for subcategories display on category selection (what's the DB structure then for categories and subcategories),
      or you might want to select a category submit and get a subcategory list...
      {{ DiscussionBoard.errors[7724831].message }}
      • Profile picture of the author rrahman
        Originally Posted by viescripts View Post

        SteveSRS is right, your problem is not very clear.

        Do you want to know what DB structure to use for categories/subcategories and the way of relations between them,
        or do you want a solution for subcategories display on category selection (what's the DB structure then for categories and subcategories),
        or you might want to select a category submit and get a subcategory list...
        I am working with Relation Database... like this:

        Subcategory
        Parent categoty (id) > category (id).

        And I want when a user click or select a category from category list, all the subcategory of that selected category will display on sub category menu...

        Similar with directory link submitted system.. someone click on main category after that subcategory option display.

        Hope my problem is now clear.
        {{ DiscussionBoard.errors[7725545].message }}
  • Profile picture of the author SteveJohnson
    What you'll need to do is some behind the scenes javascript. Disable the subcat dropdown so that people are forced to choose top-level cat first.

    When first cat is chosen, use AJAX to query for subcats of the chosen category. Or, if you don't want to use AJAX, you can build select boxes for all of the subcats, grouped by category parent, with css display:none. Then use onchange event on the main cat select to turn on the proper subcat select section.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[7725489].message }}
    • Profile picture of the author kevintb7
      Originally Posted by SteveJohnson View Post

      What you'll need to do is some behind the scenes javascript. Disable the subcat dropdown so that people are forced to choose top-level cat first.

      When first cat is chosen, use AJAX to query for subcats of the chosen category. Or, if you don't want to use AJAX, you can build select boxes for all of the subcats, grouped by category parent, with css display:none. Then use onchange event on the main cat select to turn on the proper subcat select section.
      This is right, use AJAX, they have a control tool kit for .NET which makes this really easy. But since your using php, youll have to find a version for that.

      Basically youll need a SQL query with a where clause controlled by the first drop down. I can show you how to do it in ASP.NET and MSSQL. What are you on a Windows or Unix based server? What is your database MSSQL, MySQL, ...?
      {{ DiscussionBoard.errors[7879012].message }}
  • Profile picture of the author FirstSocialApps
    I think what your saying is that you have a drop down with categories and then want the sub categories to show based on the category selection.

    There are a couple ways to do this one is with JQUERY
    Chained Selects jQuery Plugin

    Another would be with PHP/JS ala AJAX
    {{ DiscussionBoard.errors[7726679].message }}
    • Profile picture of the author rrahman
      Originally Posted by FirstSocialApps View Post

      I think what your saying is that you have a drop down with categories and then want the sub categories to show based on the category selection.

      There are a couple ways to do this one is with JQUERY
      Chained Selects jQuery Plugin

      Another would be with PHP/JS ala AJAX
      Can you please help me to get data from mysql database in below script...? I mean there are custom/fixed value in <select> <option>.. I want to get value from my database in option field and run that script

      HTML Code:
      <!DOCTYPE html> 
      <html>
      <head>
      <script type="text/javascript">
      
      function populate(s1,s2){    
      var s1 = document.getElementById(s1);    
      var s2 = document.getElementById(s2);    
      s2.innerHTML = "";    
      if(s1.value == "Chevy"){       
       var optionArray = ["|","camaro|Camaro","corvette|Corvette","impala|Impala"];    } else if(s1.value == "Dodge"){       
      var optionArray = ["|","avenger|Avenger","challenger|Challenger","charger|Charger"];    } else if(s1.value == "Ford"){        
      var optionArray = ["|","mustang|Mustang","shelby|Shelby"];    }    
      for(var option in optionArray){        
      var pair = optionArray[option].split("|");        
      var newOption = document.createElement("option");        
      newOption.value = pair[0];        
      newOption.innerHTML = pair[1];        
      s2.options.add(newOption);    }
      }
      </script>
      </head>
      <body>
      <h2>Choose Your Car</h2>
      <hr />
      Choose Car Make:
      <select id="slct1" name="slct1" onchange="populate(this.id,'slct2')">  
      <option value=""></option>  
      <option value="Chevy">Chevy</option>  
      <option value="Dodge">Dodge</option>  
      <option value="Ford">Ford</option>
      </select>
      <hr />
      Choose Car Model:
      <select id="slct2" name="slct2"></select>
      <hr />
      </body>
      </html>
      {{ DiscussionBoard.errors[7761945].message }}
  • Profile picture of the author lordspace
    I'd say if you're not too deep in the project maybe you can try using WordPress as a framework. It has the categories other other taxonomies built-in.
    Signature

    Are you using WordPress? Cool. Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[7891171].message }}
Avatar of Unregistered

Trending Topics

  • 1 {{ upvoteCount | shortNum }}

    New illustrations by Anna Podekova

    anipo in Web Design

    Hi. I am Anna and I am searching advises how to grow my traffic to my portfolio. I still don't sale much. Any advises?

  • 1 {{ upvoteCount | shortNum }}

    How to stop limiting beliefs ?

    spartan14 in Personal Development

    Hy all great warriors .The problem with me its that i have some limiting beliefs from childhood that dont let me to succed .When i try to work hard in ... [read more]

  • 2 {{ upvoteCount | shortNum }}

    CPA Networks with Pet Offers

    gorxen in Ad Networks

    Hey warriors, I'm interested in working the Pets niche, does anybody know of a CPA network or several networks that have at least a handful of good pet oriented offers? ... [read more]

  • 9 {{ upvoteCount | shortNum }}

    Are the WSO programs in the WSO section legit?

    Hello I am new to this forum and IM in general How legit are the programs being advertised and promoted in the WSO section of WF? How can I sift ... [read more]

  • 148 {{ upvoteCount | shortNum }}

    Tons of Bad Advice In This Thread

    Most people that come to the forum are looking for advice on how to build their business or to otherwise make more money. Thanks to all those willing to help ... [read more]