Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Multiple form input (php)

  • 15-07-2009 2:00am
    #1
    Registered Users Posts: 871 ✭✭✭


    Hey, Is it possible to have an input form where users can select a few different options, but then each option can be used separately from the mysql database? That probably doesn't make sense so i'll give an example.

    Person 1 selects three things from the form, A B and C.
    Person 2 selects two things B and X.
    Person 3 selects three things, A, X and Y.

    I want the php to be able to check if any of the selections from person 1 match any of the selections from the other two.

    At the moment all i can think of is say giving the choice of three different drop-down menus and each going into a different column of the database, but then if someone wanted to add a 4th it would need more columns.

    Does any of that make sense?:o


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Not even remotely :) Are you going to store the results of the choices from the different people on a database table? If so then it doesn't really matter how many items they select as long as each person has a unique id.

    Suppose I have one table called options (id, name) which you will use to generate the list of options that a user can select from and another table users (id, name, surname, username, password) that is used to allow the user to log on to the selection page.

    Now we can create a third table called choices (id, user, option, datestamp) which we store the options the user selects. Each option picked takes up one row on the choices table, so if the user selects 3 options s/he has 3 rows on the choices table, if s/he picks 2 options then s/he has 2 twos rows on the choices table etc.

    Now, all you need to do is create a query that checks if the choices one person has made are the same as the choices another person has made. If you're using a scripting language it might be easiest to take the id of the options picked by each person to generate a string and then compare the strings to see if any match up.

    For example suppose person 1 selects options 1,5 & 7. And person 2 selects options 1,2 and 4 then the strings generated would be 1,5,7 and 1,2,4. When we do a string compare on these they don't match so the users didn't select the same items. Now suppose person 3 selects options 1,5, and 7. Then their string would be 1,5,7 and so would match the string of person 1.

    I'm sure there's an easier way to do this and no doubt someone will be along to suggest it shortly. Hope what I've posted has been some help anyways :)

    Regards,
    RD


  • Registered Users Posts: 871 ✭✭✭gerry87


    I think i understand what you mean, so when someone makes one of the choices it puts a new number in that string? I don't think it's exactly what I need, unless you can compare parts of the string separately.

    Like in your example, person 1 selects 1, 5 and 7 and person 2 selects 1, 2 and 4. I'm looking to compare each element of the string against the others, to see if any match (so in that case the two 1's match).

    The actual application would be more as follows.

    Person A is looking for a set of golf clubs and offering a pool table. And person B is looking for a pool table and offering a set of golf clubs. So they're returned as a perfect match.

    At the moment I have person A selecting from two drop down menus, one for 'offering' and one for 'seeking'. It then compare's person a's choices with everybody elses choices and gives results.

    The problem i'm having is that it doesn't allow for people to be offering more than one thing at a time. If I want to allow two thing, i've to set up two 'offering' boxes and two 'seeking' boxes, so add two more columns to the database.

    So i'm looking for a generic way that people can select as many things as they want in say 'offering', but it can still check each one separately, it doesn't just check the whole thing as a string.

    Sorry, I'm making this sound a lot more confusing than it is. I'll try and think of a better way to explain it... maybe with pictures!


  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭Eoin


    Make the dropdown lists so a user can select multiple options from either one. That should give you a comma seperated list of values. You can then split that into different rows in the database.


Advertisement