Page 1 of 1

drop down menu from database

Posted: Mon Sep 15, 2008 7:10 am
by pagegen

Code: Select all

<td><select name="Select2">
                        
                        <?php
                        
                
                // SQL query to select the rows
                $queryC = "SELECT * FROM TblCat ";
                $resultC = mysql_query ($queryC);
 
                while($rowC = mysql_fetch_array($resultC,MYSQL_ASSOC))
                {
                Echo '<option value="' . $rowC[Id] . '">' . $rowC[catName] . '</option>';
                $items = $rowC[Id];         
                
                }
                
 
                    ?>
                        
                        </select></td>
                    </tr>
                    <tr>
                        <td style="width: 148px">Sub-Category </td>
                        <td><select name="Select3">
                        <?php
                        
                
                // SQL query to select the rows
                $querySC = "SELECT * FROM TblSubCats WHERE main = '$items'";
                $resultSC = mysql_query ($querySC);
 
                while($rowSC = mysql_fetch_array($resultSC,MYSQL_ASSOC))
                {
                Echo '<option value="' . $rowSC[id] . '">' . $rowSC[sub] . '</option>';
                            
                }
                
                
 
                    ?>
                        </select>&nbsp;</td>
 
Hey guys.. I have 2 drop downs
1 has main cat and the 2nd has sub cat
i want the code to look at what they select in box1 and then in box2 only show the fields that have the same id as box1

if not making sence have a look at this

database table Cat has 2 fields Name, Id
Table subCat has fileds Id and then catId

when the user selects item 1 in cat dropdown menu it shoul show all the items that have the same catId in subCat table


Thanks

Re: drop down menu from database

Posted: Mon Sep 15, 2008 7:40 am
by pcoder
I think it's a Ajax type stuff.

Re: drop down menu from database

Posted: Mon Sep 15, 2008 8:37 pm
by califdon
pagegen wrote:Hey guys.. I have 2 drop downs
1 has main cat and the 2nd has sub cat
i want the code to look at what they select in box1 and then in box2 only show the fields that have the same id as box1
If you can figure out how to make PHP, a server language, look at what a user does after the page has left the server, you can win the Nobel Prize for Computing! OK, I'm being sarcastic, I apologize. But you have to understand that PHP is no longer in the file, once it has been sent to the browser. Take a look at the "source code" of a PHP page that you're looking at in your browser. There's no PHP in it anymore! It was all executed on the server before it was sent to the browser! Anything that operates based on what the user does HAS TO BE IN A CLIENT LANGUAGE, like Javascript. The Javascript may call back to the server and execute some other PHP script, which is called Ajax. There's a lot of information online about Ajax.