hmark Posted January 12, 2010 Share Posted January 12, 2010 I'm trying to insert a dropdown menu on my webpage. THis is what I have right now: [code=php:0] <tr> <td>System:</td> <td><select name="system"> <option value=""> </option> <? $arr_system = getFldArray("system"); foreach ($arr_system as $f){ print "<option value=\"$f\">$f</option>"; } ?> <td> </tr> [/code] When i execute this, I get varchar(20) as a option. Anyone have any suggestions? I know very very very little php and mysql. I appreciate any help. I hope I posted enough info (and that I posted it correctly thanks. Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/ Share on other sites More sharing options...
jeremy0 Posted January 13, 2010 Share Posted January 13, 2010 what is getFldArray? Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-993977 Share on other sites More sharing options...
hmark Posted January 13, 2010 Author Share Posted January 13, 2010 I defined it as: function getFldArray($f){ $q = "describe experts $f"; $res = run_query($q); $row = mysql_fetch_array($res); $rt = $row['Type']; $rt = preg_replace('/enum\(\'/', '', $rt); $rt = preg_replace('/\'\)/', '', $rt); $arr = explode('\',\'',$rt); sort($arr); return $arr; } Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-994243 Share on other sites More sharing options...
jeremy0 Posted January 15, 2010 Share Posted January 15, 2010 is this still an issue? Looking at your reply tonight, it looks like the mysql query is doing what it is told - list all the fields and their type(s) - which is why you end up with 'varchar(20)' - that's the data definition of that field. Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-995311 Share on other sites More sharing options...
hmark Posted January 29, 2010 Author Share Posted January 29, 2010 Yes, this is still an issue. Do you know how i can correct this properly? Thank you. Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-1003808 Share on other sites More sharing options...
jeremy0 Posted January 31, 2010 Share Posted January 31, 2010 what I was trying to say earlier was, the mysql query you are running is saying 'describe this field', and the description of those fields in the database is 'varchar[20]'. You need to run a query on the actual data, i.e. 'select type from experts..' or whatever data you are trying to fetch from the sql statement.... Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-1004518 Share on other sites More sharing options...
clay1 Posted January 31, 2010 Share Posted January 31, 2010 This is what I use for one <select name="market"> <option value="none" selected>Please select a market</option> <?php //for each row we get from mysql, echo a form input while ($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['market']."\">{$row['market']}</option>\n"; } ?> </select> $result is just a select all on the markets table Link to comment https://forums.phpfreaks.com/topic/188275-drop-down-menu/#findComment-1004523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.