ranlo
ranlo

Reputation: 19

instead of the input being in a text box, i would like it to have a drop down list where the choices are from the mysql table

    <html>
            <body>
            Organization Name: <input type="text" name="org_name" /><br />
    Position:<input type="text" name="position" /><br/><br/>
    <input type="submit" /><br><br>
    <STRONG>Result</STRONG>
    <?php
    $con=mysql_connect("localhost","root","");

    if(!$con) {
    die('could not connect:'.mysql_error());
    }

    mysql_select_db("final?orgdocs",$con);

    $org_name = $_POST["org_name"];
    $position = $_POST["position"];

    $result = mysql_query("SELECT * FROM directory WHERE org_name = '$org_name' OR position = '$position' ORDER BY org_name");

    echo $stmt;
    mysql_query($stmt);

    echo '<TABLE BORDER = "1">';
    $result1 = $result;
    echo '<TR>'.'<TD>'.'Name'.'</TD>'.'<TD>'.'Organization Name'.'</TD>'.'<TD>'.'Position'.'</TD>'.'<TD>'.'Cell Number'.'</TD>'.'<TD>'.'Email-Add'.'</TD>';
    echo '</TR>';

    while ($row = mysql_fetch_array($result1)){

    echo '<TR>'.'<TD>'.$row['name'].'</TD>'.'<TD>'.$row['org_name'].'</TD>';

    echo '<TD>'.$row['position'].'</TD>'.'<TD>'.$row['cell_num'].'</TD>'.'<TD>'.$row['email_add'].'</TD>';
    echo '</TR>';
    }

    echo '</TABLE>';
    if (mysql_num_rows($result)>0) {
    // your thing above with mysql_fetch_array($result1) etc
    } else {
    echo 'Not found';
    }
    ?>
            </body>
            </html>

Upvotes: 0

Views: 139

Answers (1)

Sarfraz
Sarfraz

Reputation: 382806

It is simple matter of doing this:

echo '<select name="selectName">';
while ($row = mysql_fetch_array($result1)){
  echo '<option value="'.$row['fieldName'].'">' . $row['fieldName'] . '</option>';
}
echo '</select>';

Upvotes: 1

Related Questions