aebstract Posted January 17, 2008 Share Posted January 17, 2008 Alright, I am generating content for a drop down based on the information that I have stored in a database. It is very basic information, it is a table with "id", "plantloc", "password", and "address". What I want to do is generate a drop down that contains every plant. It should reference by id and should display as "plantloc". The plantloc is a nice looking description of the location, this way the user chooses their location and continues to login. Here is what I have: <?php mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $result = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC") or DIE(mysql_error()); $options=""; while ($row=mysql_fetch_array($result)) { $id=$r["id"]; $plantloc=$r["plantloc"]; $options .= "<OPTION VALUE=\"$id\">".$plantloc; } ?> <form action="account.php?menu=login" method="post"> plant loc<br /> <SELECT NAME=dropdown> <OPTION VALUE=0> <?=$options?> </SELECT> <br /><br /> password <br /> <input type="password" maxlength="6" class="textfield" name="password" size="6" /><br /><br /> <input type="submit" name="submit" class="textfield" value="login" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/86514-solved-trouble-generating-dropdown-from-mysql/ Share on other sites More sharing options...
tinker Posted January 17, 2008 Share Posted January 17, 2008 I think if you have a value and visual value then it takes this form: <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/86514-solved-trouble-generating-dropdown-from-mysql/#findComment-442062 Share on other sites More sharing options...
aebstract Posted January 17, 2008 Author Share Posted January 17, 2008 I'm not following you? I know how the drop down works, but I am trying to generate the content for the drop down from my mysql table. None of this information will be presented directly by me but rather directly from the database. Quote Link to comment https://forums.phpfreaks.com/topic/86514-solved-trouble-generating-dropdown-from-mysql/#findComment-442063 Share on other sites More sharing options...
mr_mind Posted January 17, 2008 Share Posted January 17, 2008 Alright try this on for size <?php if(mysql_connect("localhost","berryequipment","gU8Kso8Y")) { if(mysql_select_db("berryequipment_net")) { $query = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC"); $options = NULL; while($row = mysql_fetch_array($query)) { $id = $row["id"]; $plantloc = $row["plantloc"]; $options .= '<option value="$id">' . $plantloc . '</option>'; } print '<form action="account.php?menu=login" method="post">'; print 'plant loc<br />'; print '<select name=dropdown>'; print '<option value=0>----</option>'; foreach($options as $text) { print $text; } print '</select>'; print '<br /><br />'; ptint 'password <br />'; print '<input type="password" maxlength="6" class="textfield" name="password" size="6" />'; print '<br /><br />'; print '<input type="submit" name="submit" class="textfield" value="login" />'; print '</form>'; } else { print mysql_error(); } } else { print mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86514-solved-trouble-generating-dropdown-from-mysql/#findComment-442070 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.