MasterACE14 Posted September 15, 2007 Share Posted September 15, 2007 Evening, I would like to know, how to input multiple values into a single column of a MySQL field, example: fields: id - username - hobbies and input multiple values into hobbies, like so: id - username - hobbies 2 MasterACE fishing, juggling, model making How would I be able to input multiple values in the hobby column. And then how do I Select a certain value in the hobbies column, say juggling for example, how could I select that? Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/69439-solved-inputting-and-selecting-multiple-values-in-1-column-of-1-field-in-mysql/ Share on other sites More sharing options...
jagat21 Posted September 15, 2007 Share Posted September 15, 2007 For selecting multiple values for hobbies field u can use checkboxes. And @ the time of inserting record combine them in a single string. and store the value. Quote Link to comment https://forums.phpfreaks.com/topic/69439-solved-inputting-and-selecting-multiple-values-in-1-column-of-1-field-in-mysql/#findComment-348922 Share on other sites More sharing options...
MasterACE14 Posted September 15, 2007 Author Share Posted September 15, 2007 I know I can select it using a check box, but the mysql_query, would normally be like this: mysql_query("SELECT `hobbies` FROM `users`"); how do i do the same query, but selecting individual values within hobbies? Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/69439-solved-inputting-and-selecting-multiple-values-in-1-column-of-1-field-in-mysql/#findComment-348923 Share on other sites More sharing options...
jagat21 Posted September 15, 2007 Share Posted September 15, 2007 After firing the select query u have written, "select hobbies from tablename ", u can use explode() function in order to get the individual values of each hobbies. i.e. u have stored following values of hobbies in database table : id ..... hobbies 1...... reading, music, cricket now after selecting this record from query, $hobbies = explode(',',$row['hobbies']); this will give u an array of all hobbies that u have stored in single field. so u can access individual hobbies as an array elements. Quote Link to comment https://forums.phpfreaks.com/topic/69439-solved-inputting-and-selecting-multiple-values-in-1-column-of-1-field-in-mysql/#findComment-348925 Share on other sites More sharing options...
MasterACE14 Posted September 15, 2007 Author Share Posted September 15, 2007 Excellant! Thanks man, much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/69439-solved-inputting-and-selecting-multiple-values-in-1-column-of-1-field-in-mysql/#findComment-348928 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.