fazlionline Posted February 6, 2009 Share Posted February 6, 2009 Hello DearI can make a drop down menu in Dreamweaver CS3, but it has a lot of links which made load on my page at browsing time.Is this possible to make such drop down menu which can take its values from a database?Need help Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2009 Share Posted February 6, 2009 Of course it's possible. A single option for a dropdown menu needs a name and a value, so as long as you have some table in a database that has 2 fields in it (or only one if you want to use the same value for both), you can get the records and use a loop to print out the options. Link to comment Share on other sites More sharing options...
fazlionline Posted February 7, 2009 Author Share Posted February 7, 2009 thanks dearbut what is that "single option"if you please tell me a little about it, i will try it or seach google for that.or if you have that codeplease tell me about itneed help Link to comment Share on other sites More sharing options...
webtrix Posted February 7, 2009 Share Posted February 7, 2009 I'm no coder but I think I've seen something like this echo "<select>";foreach ($brandName as $brandName) echo "<option name="brand" value="$brandID">$brandName</option>";endforeach;echo "</select>"; or maybe it's ($row as $brandName)..So every single option has it's own name and unique value (id).. Link to comment Share on other sites More sharing options...
jlhaslip Posted February 7, 2009 Share Posted February 7, 2009 Which thread do you want an answer from?Here at the w3schools? or http://www.killersites.com/forums/topic/60...rom-a-database/ ? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 7, 2009 Share Posted February 7, 2009 but what is that "single option"This is a single option:<option value="the value">the label</option>It has a label, and a value. If you get your labels and values from the database you can use a loop similar to the one webtrix posted to write each option. Do you have a database set up? Do you have code to get data from the database? Link to comment Share on other sites More sharing options...
fazlionline Posted February 8, 2009 Author Share Posted February 8, 2009 You think this will work<option value="the value">the label</option>To change it like<option value="http://www.yahoo.com">Yahoo</option>Till now I do not have a database, I can work with MySQL database, but I am beginner. I want to know the code how to put these values in database, and other code how to get values from database in PHP.My code in PHP is <table><tr> <td><select name="favs1" onchange="window.open(this.options[this.selectedIndex].value)"><option>Selct a link</option><option value="http://www.usaidcdp.org">UCDP</option><option value="http://www.abtassociates.com">EAALP</option><option value="http://www.aed.org/News/Stories/glpnetstory.cfm">HEPA</option><option value="http://www.acdivoca.org/acdivoca/PortalHub.nsf">ARIES</option><option value="http://www.ardinc.com">ALGAP</option></select></td></tr></table> Is this code right? Link to comment Share on other sites More sharing options...
fazlionline Posted February 8, 2009 Author Share Posted February 8, 2009 Hello Deari did not understand the codewill you plz write the full code for meplz help Link to comment Share on other sites More sharing options...
justsomeguy Posted February 9, 2009 Share Posted February 9, 2009 In order to put the values in the database you need to either use a database admin system, like phpMyAdmin, where you can create your table and insert records into it, or you need to build a form and a processing script. The form contains the fields that go in the database, whatever you want them to be (possibly just a URL and title), and the processing script just needs to get the values and use an insert statement to add to the database. If you're building a form to insert things, you'll also want to build a form to edit or delete things already there.If you have something like phpMyAdmin installed on the server, I suggest you look there first. You can already do all of this through phpMyAdmin. If you need to build the forms yourself, look at the PHP Forms tutorial on the w3schools site for information about that.http://www.w3schools.com/php/php_forms.aspThe section about using PHP with MySQL will tell you about how to connect to the database server with your username and password, select your database, and use it.http://www.w3schools.com/php/php_mysql_intro.aspTo display the entries from the database, assuming you are already connected to the database, you would just need something like this: $result = mysql_query('SELECT label, val FROM links');while ($row = mysql_fetch_assoc($result)){ echo '<option value="' . $row['val'] . '">' . $row['label'] . '</option>';} That assumes that you have a table in the database called "links" with fields called "label" and "val". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.