cljones81 Posted March 8, 2008 Share Posted March 8, 2008 Hi Everyone: I hope someone, can help me with this problem as its got me baffled: What I am trying to create is a MySQL database administration page where the user will select a database from a combo box and the next combo box will be automatically populated with the field ids for that database e.g. Username and Password and not the associated data that each column contains. The user will then enter the search criteria based on the selected item e.g. Username = Paul. This information will be stored into a variable contained within an SQL query e.g. $result = "select * from $dbname where $fieldid = $searchid"; which will be called as part of a PHP script when the submit button is clicked. All of this I can do I just cannot think of how to get the combo box to be automatically populated with the field ids and not the associate contents ??? Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/ Share on other sites More sharing options...
cytech Posted March 8, 2008 Share Posted March 8, 2008 Try Describe. http://dev.mysql.com/doc/refman/5.0/en/describe.html Sorry for not a more detailed answer - I'm in the middle of running out the door hehe Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/#findComment-487111 Share on other sites More sharing options...
cljones81 Posted March 8, 2008 Author Share Posted March 8, 2008 Thank you for the reply, further too this, I have managed to echo out the field names of the selected database using this code: $result = mysql_list_fields($database, $dbtable); $number_fields = mysql_num_fields ($result); if (!$result){ echo "not result"; return false; } echo "Table '$dbname' in database '$database'"; for ($index=0; $index < $number_fields; ++$index) { echo mysql_field_name ($result, $index); } I have tried many ways of getting this information into a listbox for further selection by the user and none of them worked so please help me. Once again thank you Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/#findComment-487304 Share on other sites More sharing options...
cljones81 Posted March 9, 2008 Author Share Posted March 9, 2008 Hi I've been playing around with my code and I came up with this: echo "Table '$dbname' in database '$database'"; for ($index=0; $index < $number_fields; ++$index) { $fields = mysql_field_name ($result, $index); } echo "<body text='#0033FF'> <form name='form1' method='post' action=''> <label> <select name='select'> <option value='$fields'>$fields</option> <option value='$fields'>$fields</option> <option value='$fields'>$fields</option> </select> </label> </form>"; Which will return the last element in the array and print it out as options, I tried this believing that it would print out the first element in the array $field[0], but instead it only printed out the first character, in the last element of the array. My apologises, this may seem like a rather simple question, but my programming is a tad rusty but is there anyway, I can access and print out the first element and so on in the array. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/#findComment-487736 Share on other sites More sharing options...
wildteen88 Posted March 9, 2008 Share Posted March 9, 2008 You need to echo the <option></option> HTML tags within the for loop: <?php echo "Table '$dbname' in database '$database'"; echo "<body text=\"#0033FF\"> <form name=\"form1\" method=\"post\" action=\"\"> <label> <select name=\"select\">\n"; for ($index=0; $index < $number_fields; $index++) { $field = mysql_field_name ($result, $index); echo " <option value=\"$field\">$field</option>\n" } echo ' </select> </label> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/#findComment-487758 Share on other sites More sharing options...
cljones81 Posted March 9, 2008 Author Share Posted March 9, 2008 Thank you to wildteen88 that was exactly what I was missing and so obvious when I think about it and also a big thank you to Cytech, for pointing me in the right direction in the first place Quote Link to comment https://forums.phpfreaks.com/topic/95098-populating-a-listbox-with-field-names/#findComment-487803 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.