...

View Full Version : Simple issue?



Kal
06-16-2006, 01:42 PM
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.



$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>";

Spookster
06-16-2006, 01:49 PM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)

Spookster
06-16-2006, 01:56 PM
Why don't you just do this?




$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.

Kal
06-16-2006, 02:06 PM
Sorry i will be more descriptive next time.

any ideas on how i would validate that?

Spookster
06-16-2006, 03:24 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum