drop down menu from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pagegen
Forum Commoner
Posts: 32
Joined: Sat May 31, 2008 6:38 am

drop down menu from database

Post 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
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: drop down menu from database

Post by pcoder »

I think it's a Ajax type stuff.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: drop down menu from database

Post 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.
Post Reply