SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    Scotland
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Putting data in drop down.

    Okay, have been trying to get this to work for a while now.

    What I am doing is searching in mysql database for a surname, taking all of them and dropping them into a drop down box for selection.

    I have had to refer to a couple of books to get thus far and it all seems to work out but the form wont display, I figure its becuase I am way ahead of my thinking in terms of the script but I just want to see that it populates the drop down properly.

    Anyone see why the form is not displaying?

    PHP Code:
    <?PHP

    // Create connection to access database
    $link mysql_connect('localhost''username''password');
    if (!
    $link) {
       die(
    'Not connected : ' mysql_error());
    }

    // make memorial the current db
    $db_selected mysql_select_db('memorial'$link);
    if (!
    $db_selected) {
       die (
    'Unable to Connect');
      }

    if (
    $_POST[exists] != "true") {
        
    //If $_POST is empty, the I have not selected a name, so show the form.

    //  Request the surnames using UNIQUE
    $get_surnames "SELECT DISTINCT surname from runnymede";
        
    $surname_results mysql_query($get_surnames) or die (mysql_error());
        
    if (
    mysql_num_rows($surname_results) < 1) {
        
    //No Records Found
        
    $display_block .= "<p><em>Sorry, No results found.</em></p>";
        
        } else {
        
        
    //Yup, found records, lets get results and put the in a form.
        
    $display_block .= "
        <form method=\"post\" action=\"
    $_SERVER[PHP_SELF]\">
        <P>Select a surname:<br>
        <select name=\"sel_surname\">
        <option value=\"\">-- Select --</option>"
    ;
        
        while (
    $recs mysql_fetch_array($surname_results)) {
        
    $surname $recs['surname'];
        
        
    $display_block .= "<option value=\"$surname\">
            
    $surname</option>";
            
        }
        
    $display_block .= "
        </select>
        <input type=\"hidden\" name=\"op\" value=\"view\">
        <p><input type=\"submit\" name=\"submit\"
            value=\"View Surname Records\"></p>
        </FORM>"
    ;



    } else if (
    $_POST[data] == "true") {

        
    //check for required fields
        
    if ($_POST[sel_surname] == "") {
            
    header("Location: search.php");
            exit;
            
        }
        }
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo $display_block

  3. #3
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah you need to output the data (options tags) to the page.

    Quote Originally Posted by Bas!
    PHP Code:
    echo $display_block

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    Scotland
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, how obvious was that, I am suitably disgraced!

    Thanks to both

    Lee


Bookmarks

Posting Permissions

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