Results 1 to 5 of 5

Thread: drop down list and mysql

Threaded View

  1. #1

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    drop down list and mysql

    I am just starting.. .I am facing difficulty in solving a simple issue. Please help me with code.

    There is a table with names of individuals and their addresses. Say, the column 1 is name, column 2 is add1, column 3 is add2.

    I want a simple program in php that would display the ordered list of individual names in a drop down list.When the user selects one of them and submits it via a form, mysql should locate the record that matches the name and display the address (add1 and add2).

    simple, but I am not getting it right.

    I am getting the code to display the drop down list from the table, but when selected, only half of it is getting posted. Say, the name is Anthony Gonzalves in the list, when clicked, only Anthony gets passed and hence it does not match any record in the table. What is happening?

    Here is the code:

    PHP Code:
    $con= mysql_select_db("bacteria");

    $alln = @mysql_query('select name from detail order by name desc');

    if (isset($_POST['button'])){
        $select=$_POST['selecty']; 

        $result=mysql_query("select * from detail where name='$select'");
        if (mysql_num_rows($result) == 0) {
            die ("No rows found!");
        }
        while($row=mysql_fetch_assoc($result)) {
            print_r($row);
            echo ($row['Add1']);
            echo ($row['Add2']);
        }

        mysql_free_result($result);
        mysql_close(); 

    } else {

    ?>
    <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 

    <select name="selecty">

    <?php
    while($nm=mysql_fetch_array($alln)){
        echo (
    "<option value=".$nm['name'].">".$nm['name']."</option>");
    }
    ?> 
    </select>

    <input type="submit" name="button" value="Submit" />
    </form>
    <?php
    }

    ?>
    Last edited by sridharao; Nov 2nd, 2008 at 11:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width