PDA

View Full Version : 2 Questions


Dave
08-02-03, 03:02 AM
Hello Guys and Gals,
I've got to quick PHP questions..

I want for a user to be able to select multiple languages from a list and I want those values to be inputted into a MYSQL table. So if the users selects English and Chinese, the language column will contain "English, Chinese." I want the values to be comma separated.
<select size="3" multiple>
<option value="English">English</option>
<option value="Arabic">Arabic</option>
<option value="Chinese">Chinese</option>
</select>

Next, I want users to be able to search a database with multiple requirements, possibly with checkboxes. So, for example, the users wants to search for the row in which the "Car" column = "BMW" or the "WebSite" column = "Yes".

Thanks for the help guys!

NickDev
08-08-03, 06:06 AM
SELECT * FROM table WHERE Car = 'BMW' like so?

dont forget to put a name on your select box name="language"
$lang = addslashes($_POST['language']);
INSERT INTO table (language)VALUES('$lang')

soapsud
08-08-03, 06:18 AM
Hi Dave,

on the first question, i'd strongly suggest using a lookup table instead, it's better database design and may help your queries later in life.

ie, 3 tables:

user {id}
languages {id, language}
user_languages {user_id, language_id}

(i'm assuming you have a user table, as that seems to be where you're going with it?)

so instead of storing (as i assume)

user {id, language}

where language is a comma delimeted field, you insert rows into the "user_languages" table such that:

Bob (id 4)
speaks chinese, english (CHI, ENG)

user_languages:
user_id language_id
4 CHI
4 ENG

anyhow, if you're not using a user table (or something similar) ignore this :)

Dave
08-09-03, 12:57 AM
Originally posted by soapsud:

Hi Dave,

on the first question, i'd strongly suggest using a lookup table instead, it's better database design and may help your queries later in life.

ie, 3 tables:

user {id}
languages {id, language}
user_languages {user_id, language_id}

(i'm assuming you have a user table, as that seems to be where you're going with it?)

so instead of storing (as i assume)

user {id, language}

where language is a comma delimeted field, you insert rows into the "user_languages" table such that:

Bob (id 4)
speaks chinese, english (CHI, ENG)

user_languages:
user_id language_id
4 CHI
4 ENG

anyhow, if you're not using a user table (or something similar) ignore this :) That's a bit too complicated...