Web Analytics Made Easy -
StatCounter A REAL STUMPER.... PHP/mySQL/Javascript Combo Box Script - CodingForum

Announcement

Collapse
No announcement yet.

A REAL STUMPER.... PHP/mySQL/Javascript Combo Box Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A REAL STUMPER.... PHP/mySQL/Javascript Combo Box Script

    Okay, first of all, I am building a game database system, I wanted to filter out all the games by choosing which gaming system (ps2, xbox, etc...) so if someone chose xbox then the combo box beside it would list all of the games for xbox : http://www.javascriptkit.com/script/cut183.shtml

    Thats the javascript part...
    Now I have a PHP system that adds games, and gaming systems.

    I wanted this script to be able to list the games and gaming systems from the database.

    This one is a real stumper, and I dont know if I confused any of you But if anyone is kind enough to help please do.

    Thanks
    Please visit http://www.thickandthinpizza.com and tell me what you think.

  • #2
    I have pages where i use such a interdepended dropdows (possebly infinit number of dropdowns) by using a javascript array, that is dynamically build from a recordset.

    Now, i only use this is the arrays are relatively small (so if the dropdowns don't have two many options and then especially the total number of options for your last dropdown) and if the other codinglogic for that page is to complex to reload the page and if i'm sure that using javascript wount be a problem for potential users (so only when i have a known usergroup).

    Else i just post the page to itself and proces the filled in dropdown, use the choosen options as conditions in a select. Build the new dropdown, and display.

    If at all possible, i'd take the complete serverside method because it is universal and you can use it with large recordsets.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      could you possibly show me, because im a newb lol
      Please visit http://www.thickandthinpizza.com and tell me what you think.

      Comment


      • #4
        Which of the two alternatives?

        Through a javascript array or completely serversided ?
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          I am going to have to use all of them... Javascript to do the DropDown Double Combo Box, and PHP to get the games listed from the Database... This is an example:

          http://www.gamingfactor.com/example.html

          You see how if you choose Xbox, the other Drop Down has XBox games and etc...

          The thing I need diffrent is I need the Games and Systems to be loaded from the Database instead of put in manually...
          Please visit http://www.thickandthinpizza.com and tell me what you think.

          Comment


          • #6
            Originally posted by thickandthin
            The thing I need diffrent is I need the Games and Systems to be loaded from the Database instead of put in manually...
            To builf the frirst dropdown, just run
            PHP Code:
            $select="SELECT theoptionvaluevariable, theoptionlabelvariable FROM table";
            $result mysql_query($select,$link) or die ('Queryproblem:' mysql_error()); //$link is likidentifier from your connection. can be dropped
            if (mysql_num_rows($result) < 1){
                  
            $error = ('No systems were returned.');
            } else {
                   
            $systemsdrpd=('<select name="systemsdrpd" id="systemsdrpd" size="1" onchange="submit();">');
                   
            $systemsdrpd .=('<option value="0">All</option>');
                   while(
            $row mysql_fetch_array($result)){
                         
            $systemsdrpd .= ('<option value="'$row['theoptionvaluevariable'] .'"');
                         if (
            $_POST['$systemsdrpd'] == $row['theoptionvaluevariable']){
                               
            $systemsdrpd .= (' selected="selected"');
                         }
                         
            $systemsdrpd .= ('>'$row['theoptionlabelvariable'] .'</option>');
                   }
                   
            $systemsdrpd .= ('</select>');
            }
            mysql_free_result($result); 
            To build the array, you need to give more info. Like how your system and games table is structured and if you can get bot the systems and games in one query.
            It's easier to write the code for your actual tables because i assume you can do it in one select. Then you need to order the records on the systemoption-value. You can then build the array, inside the loop you see above. Eacgh time the systemname is different as in the record befre, a new option is added to the $systemsdrpd. Else, there is only created a new array-element.

            <edit>The name of the select was wrong</edit>
            Last edited by raf; Feb 26, 2004, 07:38 PM.
            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

            Comment


            • #7
              Thanks very much. I am going to try to use that [email protected]@@
              Please visit http://www.thickandthinpizza.com and tell me what you think.

              Comment

              Working...
              X