genzedu777 Posted September 30, 2010 Share Posted September 30, 2010 Hi, I realised that it is possible to populate SQL tables VALUES out into html form? Example 1) I have a table call 'country' in my database 2) In html, I have a <form> <input name="country" type="checkbox" id="Germany" value="Germany"> <label for="Germany">Germany</label> </form> 3) If you realised, my value is currently value="Germany" 4) My question is, how can I literally pull out the value of "Germany" from my 'location' table and place it in my html form automatically, without me typing out the value for every single country. 5) Just imagine I have 50+ countries, I will require to type out 50 times the countries' name personally in the value="", is there a way to populate the 'location' table into the value="", thereafter user selects the country through what was populated from the database 'location' table and saved it under the user_id. I'm not sure if you guys know what I am talking about, but will appreciate any help. Thanks Wilson Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/ Share on other sites More sharing options...
fenway Posted September 30, 2010 Share Posted September 30, 2010 Sounds like pretty basic PHP/MySQL interaction -- lots of tutorials and examples floating around on these boards and this site in general. Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1117739 Share on other sites More sharing options...
chintansshah Posted October 1, 2010 Share Posted October 1, 2010 Find code //I hope you connect with Mysql $sql = mysql_query("SELECT * FROM country ORDER BY country_name ASC"); echo "<form>"; while($data = mysql_fetch_array($sql)) { echo '<input name="country" type="checkbox" id="'.$data['country_name'].'" value="'.$data['country_name'].'"> <label for="'.$data['country_name'].'">'.$data['country_name'].'</label>'; } echo "</form>"; Please let me know if you have any error. Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1117863 Share on other sites More sharing options...
genzedu777 Posted October 1, 2010 Author Share Posted October 1, 2010 Hi chintansshah, Thanks, this is what I am looking for, I will try it out. Wilson Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1117905 Share on other sites More sharing options...
genzedu777 Posted October 7, 2010 Author Share Posted October 7, 2010 Hi, I have a question regarding about this, I may call forth the country name to appear in my HTML form, however the value which I would like them to capture is the country_id, instead of the country_name. Will it complicate the code, is it feasible? Thanks $sql = mysql_query("SELECT * FROM country ORDER BY country_name ASC"); echo "<form>"; while($data = mysql_fetch_array($sql)) { echo '<input name="country" type="checkbox" id="'.$data['country_name'].'" value="'.$data['country_id'].'"> <label for="'.$data['country_name'].'">'.$data['country_name'].'</label>'; } echo "</form>"; Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1119763 Share on other sites More sharing options...
chintansshah Posted October 10, 2010 Share Posted October 10, 2010 sorry, but I don't understand your question Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1120754 Share on other sites More sharing options...
genzedu777 Posted October 10, 2010 Author Share Posted October 10, 2010 oh okay, Allow me to explain it properly. In the database there is a "country" table. It has coulums of country_id and country_name. <input name="country" type="checkbox" id="'.$data['country_name'].'" value="'.$data['country_id'].'"> <label for="'.$data['country_name'].'">'.$data['country_name'].'</label> "country" table is a many-many relationship with "user" table, hence I thought of grabbing the values in numeric form, and place it in a new table called "country_user", that is the reason why I would like the return value to be in numbers instead of words. Do you roughly understand what I am saying? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1120769 Share on other sites More sharing options...
fenway Posted October 10, 2010 Share Posted October 10, 2010 What does this have to do with user? Quote Link to comment https://forums.phpfreaks.com/topic/214824-database-table-to-be-incorporated-into-html-form-value/#findComment-1120801 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.