473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

many choices

Hi all,

don't know if I must ask in a mysql NG, but this seems more a php question.

I've to provide a group of items the user may select or not (checkboxes).
The user may choose from 0 to 35 choices and can select more than 1 choice
at a time. (multiselect possible).

How to store and retrieve on a mysql field ? how to automate this ? must I
put in an array, how to build the query ?

Thanks for help.

Bob

Apr 2 '07 #1
4 1258
Bob Bedford wrote:
Hi all,

don't know if I must ask in a mysql NG, but this seems more a php question.

I've to provide a group of items the user may select or not (checkboxes).
The user may choose from 0 to 35 choices and can select more than 1 choice
at a time. (multiselect possible).

How to store and retrieve on a mysql field ? how to automate this ? must I
put in an array, how to build the query ?

Thanks for help.

Bob
Bob,

You're looking at a many-to-many relationship here - you have more than
one user, and more than one checkbox.

Database normalization rules (a good thing to look up) show that you
need a separate table to hold the relationship.

So you would have a table with the user information, a table for the
checkbox descriptions (unless they would never, in a million years,
change) and a third table with entries for a userid and a selected checkbox.

Probably the easiest way is to get the data from the HTML code as an
array and insert each element into the table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 2 '07 #2
You're looking at a many-to-many relationship here - you have more than
one user, and more than one checkbox.
Absolutely not...You message tell me I didn't explain very well, that's my
fault sorry.

I've a page where a user can choose what it does like (it's interest
points).
For example:
soccer,
football,
baseball,
tennis,
rugby,
swimming....

So the user may choose none or many things he is interested in and I've to
store in his profile.
I don't know how to manage this. Every item has its own number but I don't
know how to save in a mysql field (wich kind of field must I use) and also
how to save from the form where the items are shown to the DB (the query).
Also how to retrive those items back when the user want to edit his profile.

Thanks for help

Apr 2 '07 #3
Bob Bedford wrote:
>You're looking at a many-to-many relationship here - you have more than
one user, and more than one checkbox.
Absolutely not...You message tell me I didn't explain very well, that's my
fault sorry.

I've a page where a user can choose what it does like (it's interest
points).
For example:
soccer,
football,
baseball,
tennis,
rugby,
swimming....

So the user may choose none or many things he is interested in and I've to
store in his profile.
I don't know how to manage this. Every item has its own number but I don't
know how to save in a mysql field (wich kind of field must I use) and also
how to save from the form where the items are shown to the DB (the query).
Also how to retrive those items back when the user want to edit his profile.

Thanks for help
Yes, you have more than one user, and more than one selection. This is
a many-to-many relationship (many users, many selections). My comments
are correct.

Do some searches on "database normalization".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 2 '07 #4
On Apr 2, 3:56 am, "Bob Bedford" <b...@bedford.comwrote:
Hi all,

don't know if I must ask in a mysql NG, but this seems more a php question.

I've to provide a group of items the user may select or not (checkboxes).
The user may choose from 0 to 35 choices and can select more than 1 choice
at a time. (multiselect possible).

How to store and retrieve on a mysql field ? how to automate this ? must I
put in an array, how to build the query ?

Thanks for help.

Bob
Bob,

One easy yet difficult solution may be to have a field called "sports"
and inside of it, store something like 001011... where each number
represents each sport. So soccer is position 1, football is position
2, etc. Then when you want to display that information you can have
some simple case of if/then statements inside of a loop looking at
positions and values. For example, "if substr(sports,0,1) == '1' then
echo 'soccer';" etc. This isn't the prettiest solution and you will
have major issues on your hands if you ever add or remove a sport.

The solution I would choose, as mentioned by Jerry, is to have another
table where you can relate the two. Say my user_id is 1, and each
sport has a sport_id, and I had three sports with the sport_ids 3, 5,
and 6. You could have a table that just had the user_id and sport_id
fields: One record would be user_id 1, sport_id 3. The next record
would be user_id 1, sport_id 5... and so on. Then when you need to
query which sports user 1 has listed, you can do something like
"SELECT users_sports WHERE user_id = '1'" and you will have 3 records,
each one with a different sport_id that I have selected.

Although database normalization is the "correct" way to do things,
sometimes it isn't the easiest. In this case, it would be the easiest
to normalize your database with that middle table because if you ever
removed or added a sport, your data would be fine unlike the first
method I mentioned which would result in inaccurate data. I hope this
helps!

Apr 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Heather Stovold | last post by:
Wow - deciding to program in python sure requires a lot of decisions! So far: I've decided on python for the programming language. I've decided on wxpython for the GUI.... I've decided on...
5
by: jason | last post by:
I could sure use some conceptualization and query help with a Page Watch System I am building in Access 2000 and Asp. I need to cycle through databae and generate a compiliation query email that...
9
by: Bob C. | last post by:
I want to create a 1-many relationship. Parent table has a primary key, child table has no primary key. The child table does have an index with all four fields of the parent's PK. How can I do...
2
by: Cin | last post by:
I have a one-to-many relationship that I would like to convert to an unbound checkbox or radio buttons within a form. On form (pulls from tblEquipment) user can select one or all three choices...
6
by: BerkshireGuy | last post by:
I need to create a query that will filter out records based on records. There can be many combinations depending of what the uses selects. For instance: Field: Telemed - This is a Y or N...
9
by: Rhino | last post by:
How hard (and desireable) would it be to give the user certain choices when it comes to printing web pages? The pages on my site use colours and pictures and contain an imbedded menu, among...
2
by: rich | last post by:
I am building a database and I am using a list where I can make multiple choices. The data is like this Master table item1id item2 index(item1id) detail table item1id
4
by: wideasleep | last post by:
Hello everyone, I am looking for a way to remove choices from cascading combo boxes as each selection is made. Here's how this is laid out. The initial combo box is STAGE and it will have...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.