PHP noob with a challenge.
I have a custom php function:
function country_dropDown(){
$dropDown = mysql_query("SELECT * FROM countries");
while ($record = mysql_fetch_array($dropDown)) {
echo '<option value="' . $record['id'] . '">' . $record['name'] . '</option>';
}
}
'countries' table has 2 fields = id, name.
There are over 200 rows in this 'countries' table.
I can call this function in a html form that requires user input to select from the list of available countries from the list like this.
<select name="classID"><?php country_dropDown() ?></select>
I have some questions I hope someone can help me with.
When I call this function inside a html form and look at the source code I can see all 249 countries as "select options". Is there a best practice or efficient method so it does not list all countries in the source code?
The drop down list always displays, "Afganistan" which is the first row in the 'countries' table. How can I modify my custom function so it does not show any value or display the text, "Select Country"?
I have another table called 'student' with 2 fields: studentName, countriesID. I have a html form that lets me edit a student's record. It populates the default value of the student's name into the input text field but how do I make the dropdown function 'selected' the student's 'countryID' from the row? It always shows, "Afganistan".
Is there a best practice method or more efficient way to approach this countries dropdown select rather than my custom function?
I'm grateful for any assistance.