denoteone Posted January 26, 2008 Share Posted January 26, 2008 I have a table named strata_links and field named 'name' I would like for the php to query the database and create an array. I think i am going wrong with the query statement. it should just show a list of names with the value being the actual name itself. any help would be great thanks everyone. <? include "connect.php"; $query="SELECT * from strata_links order by name, name"; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<form name='form1' method='post' action='script.php'>\n"; echo "<select name='imagename'>\n"; while ($result = mysql_fetch_assoc($query)) { echo "<option value='".$result['name']."'>".$data['name']."</option>\n"; echo "</select>\n"; echo "<input type='submit' name='submit' value='Submit'>\n"; echo "</form>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/ Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 Not sure where you are getting $data from echo "<option value={$result['name']}>{$result['name']}</option>\n"; Also, take your submit out of the loop unless you want a submit for every option value. Can also do echo "<option>{$result['name']}</option>\n"; Pretty sure the value defaults to the field if it's omitted. Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449910 Share on other sites More sharing options...
denoteone Posted January 26, 2008 Author Share Posted January 26, 2008 the "&data" was supposed to read $result. I guess I want to make sure my mySql syntax is correct. I have taken the submit button out of the loop as well. here is my code now. <? include "connect.php"; $query="SELECT * from strata_links order by name, name"; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<form name='form1' method='post' action='script.php'>\n"; echo "<select name='people'>\n"; while ($result = mysql_fetch_assoc($query)) { echo "<option>"{$result['name']}"</option>\n"; } echo "</select>\n"; echo "<input type='submit' name='submit' value='Submit'>\n"; echo "</form>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449923 Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 You need to change some things around. <?php include "connect.php"; $query="SELECT * from strata_links order by name, name"; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<form name='form1' method='post' action='script.php'>\n"; echo "<select name='people'>\n"; while ($row = mysql_fetch_assoc($result)) { echo "<option>{$row['name']}</option>\n"; } echo "</select>\n"; echo "<input type='submit' name='submit' value='Submit'>\n"; echo "</form>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449934 Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 And this should be changed, not sure why you have a name, name $query="SELECT * from strata_links order by name"; Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449935 Share on other sites More sharing options...
denoteone Posted January 26, 2008 Author Share Posted January 26, 2008 Sorry i thought that I had to have the name of the field to get the array from in the mySQL query. In this case the name for the field is "name" In any case thanks I have it working. ??? before I start looking is it even possible to put the mySQL array in alphabetical order? before it is put in the drop down menu Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449945 Share on other sites More sharing options...
denoteone Posted January 26, 2008 Author Share Posted January 26, 2008 ok so I have my drop down but the value of <option> is not being sent to the script.php page. here is the drop down page... <?php include "connect.php"; $query="SELECT * from strata_links order by name"; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<form name='form1' method='post' action='script.php'>\n"; echo "<select name='people'>\n"; while ($row = mysql_fetch_assoc($result)) { echo "<option name='option'>{$row['description']}</option>\n"; } echo "</select>\n"; echo "<input type='submit' name='submit' value='Submit'>\n"; echo "</form>\n"; ?> Here is the script page that should show the value associated with the drop down menu <option> <? include "connect.php"; if (isset($_POST['submit'])) // name of submit button { $choice = $POST_['option']; echo $choice; } else{ print "<center>"; print "<table>"; print "<tr><td><center>please select a File first</center></td></tr>"; print "<tr><td><center>"; print "Wrong username or password or unactivated account, redirecting back to login page... <META HTTP-EQUIV = 'Refresh' Content = '2; URL =getimage.php'></center>"; print "</td></tr></table></center>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87936-solved-populating-drop-down-menu/#findComment-449997 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.