June 28th, 2000, 03:59 PM
I'm developing a database that holds information about crew members. There are 7 categories of service types. Crew members can be associated with any number of categories.
I'm working on an update form to add or delete categories for a crew member. I first issued a query to find the member's categories. I issued a second query to list all possible categories. I want to show a checkbox for any possible categories that aren't in the member's individual category list. If the member is in categories 1 and 2, but not in 3 or 4, I want to show a checkbox for categories 3 and 4.
I can get the two category lists to print, but I can't figure out how to compare them.
Here is the code I have for the select statements:
Generates the list of member categories:
$cat_query = "SELECT crew_category.crew_id, crew_category.category_id, category.category_desc
FROM crew_category, category
WHERE crew_category.crew_id = "$crew_id" and crew_category.category_id = category.category_id";
$cat_result = mysql_query($cat_query);
Generates the list of all possible categories:
$all_cat_query = "SELECT category_id
$all_cat_result = mysql_query($all_cat_query);
I'm just developing my programming skills (as I'm sure you can tell), so I apologize for my ignorance! Thanks in advance to anyone who can help!
June 29th, 2000, 02:28 AM
<< I want to show a checkbox for any possible categories that aren't in the member's individual category list. If the member is in categories 1 and 2, but not in 3 or 4, I want to show a checkbox for categories 3 and 4.
Actually i am not clear your rquestion.
crew_category.category_id = category.category_id";
you have already comparing the id's of both the tables.I don't understand why you are doing a matching again.
"The fear of the LORD is the beginning of knowledge..."
[This message has been edited by Shiju Rajan (edited June 29, 2000).]
June 29th, 2000, 09:56 AM
The purpose of the form is to edit the crew member's category information. The category table holds only the category_id and the category title. The crew_category table is a link table that holds the crew_id and the category_id (So we can add categories later).
The form displays the current categories for that crew member. If a member has entries in the crew_category table for categories 1 and 2, these will display. I want to allow the user to select categories to add for this member only for categories that don't exist for that member.
As an example, a member has the following entries in the crew_category table:
crew_id = 10, category_id = 1
crew_id = 10, category_id = 2
I want the update form to display checkboxes for categories 3,4,5, etc., but NOT for categoris 1 or 2, so categories 3,4,5 can be added.
I'm trying to compare the results of the crew_category lookup with the categories table to see what categories don't exist for this person.
Sorry about the confusion. I know what results I want, I just don't know how to go about it (or how to explain it)!