Beast27 Posted August 20, 2010 Share Posted August 20, 2010 I have set up a form page with a select box of colleges to select. I want the "options" in the select box to be values taken from a field called "name" in a table called "colleges" and they should be ordered alphabetically. I also want the default selected option to be "none." I have attached a picture to describe what i want. Please be detailed with the code. I am fairly new to php and mysql. Thank you. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2010 Share Posted August 20, 2010 Please be detailed with the code Programming help forums don't write the code for your assignments. We help you with the code you are writing. Exactly what problem, error, specific question, or point did you get stuck at when you attempted to do this? Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 20, 2010 Share Posted August 20, 2010 I'll try my best to help you - but I'm not going to spoon feed you. First thing I need to know is that are the tables in your SQL (college) already populated? By that, I mean do they already have data in them? Am I correct in thinking that you simply want to have them being placed from your SQL onto a nice organised table in which you can view on your browser? Quote Link to comment Share on other sites More sharing options...
Beast27 Posted August 21, 2010 Author Share Posted August 21, 2010 I'll try my best to help you - but I'm not going to spoon feed you. First thing I need to know is that are the tables in your SQL (college) already populated? By that, I mean do they already have data in them? Am I correct in thinking that you simply want to have them being placed from your SQL onto a nice organised table in which you can view on your browser? The tables in my SQL (college) are already populated. I have manually inserted those values. I want all the "name" fields from SQL (college) to appear as OPTIONS for a select box(alphabetically). The concept of the page as a whole is like this. There will be a list box titled "college" and the user will be able to select one of the colleges from this list box. Thats all there is to it. I am guessing I need to call a query such as: SELECT name FROM college ORDER BY name ASC Then i would have to put those values as options in my listbox. This is the code for my listbox <select name="college"> <option>college 1<.option> <option>college 2<.option> <option>college 3<.option> <option>college 4<.option> etc...all the way till the LAST college in my SQL (college) table. Im sorry for the confusion but if you have any more questions i will clarify them. Quote Link to comment Share on other sites More sharing options...
Rifts Posted August 21, 2010 Share Posted August 21, 2010 <? ... mysql cnx code ... $sql="SELECT id, thing FROM table"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $thing=$row["thing"]; $options.="<OPTION VALUE=\"$id\">".$thing; } ?> ... html code ... <SELECT NAME=thing> <OPTION VALUE=0>Choose <?=$options?> </SELECT> ... Quote Link to comment Share on other sites More sharing options...
Rifts Posted August 21, 2010 Share Posted August 21, 2010 if my last post was confusing this may help <?php $q = mysql_query("SELECT name FROM college ORDER BY name ASC"); echo "<select name='college'>"; while ($row = mysql_fetch_assoc($q)) { echo '<option value="'.$row['college'].'">'.$row['college'].'</option>'; } echo "</select>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.