Jump to content

[SOLVED] Inputting and Selecting Multiple Values in 1 column of 1 field in MySQL


MasterACE14

Recommended Posts

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.