Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.