Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Simple issue?

  1. #1
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple issue?

    The following code i have written works fine, it simply creates a drop down list which is populated from a mysql query, it display's a list of areas, and each area has a stock location and email address, all these attributes are put into an array.

    what i want to do is modify it so that the drop down displays a default option "Please Select A Branch", i am having trouble trying to get this to work.

    Any help is much appreciated. Thank You.

    PHP Code:
    $query "select brn_name,stk_loc,contact_emails from mc_mc.mc_brn_locations";

    $result mysql_query ($query) or die (mysql_error());

    echo 
    "<td><SELECT name=\"branch\">"
            
    $loc=array();

    if (
    mysql_num_rows($result)>0

    {

    while(
    $row=mysql_fetch_array($result))


            
    #The following line, puts the rsults from the query into an array called $loc.
    $loc[$row[brn_name]]=array($row[stk_loc],$row[contact_emails]);
    echo 
    "<option value=\"$row[brn_name]\">$row[brn_name]</option>"



    }

    echo 
    "</SELECT></td>"

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts

    More descriptive subject

    In the future, please use a more descriptive subject when posting a question. See posting guidelines.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Why don't you just do this?

    PHP Code:

    $query 
    "select brn_name,stk_loc,contact_emails from mc_mc.mc_brn_locations";

    $result mysql_query ($query) or die (mysql_error());

    echo 
    "<td><SELECT name=\"branch\">"

    echo 
    "<OPTION value='noselectionmade' SELECTED>Please Select A Branch</OPTION>"        
    $loc=array();

    if (
    mysql_num_rows($result)>0

    {

    while(
    $row=mysql_fetch_array($result))


            
    #The following line, puts the rsults from the query into an array called $loc.
    $loc[$row[brn_name]]=array($row[stk_loc],$row[contact_emails]);
    echo 
    "<option value=\"$row[brn_name]\">$row[brn_name]</option>"



    }

    echo 
    "</SELECT></td>"
    And of course you will want to add in some PHP code to handle the situation where they submit the form or whatever without first selecting an option.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry i will be more descriptive next time.

    any ideas on how i would validate that?

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Where is the code you are using to process the form? In there you can add in a conditional statement to check the value of that select box. So

    if (selectboxvalue != noselectionmade)

    process the form

    else

    return them to the form and let them know they need to
    select an option
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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