HI

I seem to have a problem with a drop down menu, the code seems to work fine and the values are showing in source code but do not show on the page????

Another issue is I dont know how to move forward after this to make a combo drop down box whereby the selected value of the first box then decides what is populated in the 2nd box and then a selection is made from there to go to that url.

Hope somebody can help.

    <head>
    <style type="text/css">
            #myForm select option:nth-child(odd) {
                color:orange;
                background:lightgray;
            }
            #myForm select option:nth-child(even) {
                color:orange;
                background:white;
    font-colour:orange;
            }
            #myForm select {
                background:gray;
                color:orange;
            }
        </style>
    </head>


    <body>
    <form id="myForm" action="#" method="get">
    <select name="select1">
    <option value="Select Option">Select Option</option>
    <?php
    $con = mysql_connect("","","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("Database", $con);
    $result=mysql_query("select * from TABLE where Field='whatever' ORDER BY whatever, whatever2");
    while($row=mysql_fetch_array($result))
    ?>
    <option value="<?php echo $row['whatever']; ?>" <?php echo $row['whatever2'];?></option>
    <?php                                                
    }   
    ?>  
    </select>
    </body>
    </html>

You are missing the closing > for the option, ater the last " for the value.

<option value="<?php echo $row['whatever']; ?>"> <?php echo $row['whatever2'];?></option>

Thanks
Brilliant, that now works perfectly.

Now is it possible to help me on the other matter posted which is I dont know how to move forward after this to make a combo drop down box whereby the selected value of the first box then decides what is populated in the 2nd box and then a selection is made from there to go to that url.

Are you using AJAX or posting forms?

Either , as long as it works :)

Those are the steps that you need to take care of:

Add a listener to the change event of the select.
Once changed, send the selected value to a php page (either using form submit or AJAX)
The PHP page will read the value and query the database.
If using AJAX: The PHP page will return the options. The JS handler to the AJAX will insert the options in the select
If using form submit: The PHP page will response the whole page again. This way you have to check if there's a selected value or not in the session to either show both selects or only the first.

I may be forgotting something, but that's the basic.

Obs.: I had to remove the enumeration and format because the post validation have some kind of bug.

ok thanks for your help

You're welcome.

Good luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.