Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3394172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:08:18+00:00 2026-05-18T04:08:18+00:00

Here is my table setup: employee: Employee information, name, address, etc… group: List of

  • 0

Here is my table setup:

  • employee: Employee information, name, address, etc…
  • group: List of distribution groups.
  • employee2group: table that links employees to multiple groups.

I have it setup this way so I can add groups in the future, without having to add columns to my employee table. This may seem like common sense to you all, but I just started with PHP a couple months ago, so everything is still new and confusing to me.

So, I’m working on my update form, which will display a list of check boxes that is populated with a simple SELECT * FROM group query. The idea is to show the ones that an employee is part of as “checked” when I view the employee in the update form.

Currently, my while loop to show the list of check boxes is this:

<?php
 $group_list_query = "SELECT * FROM group"
 $group_list_result = mysql_query($group_list_query, $cmsWrite)
 while ($row = mysql_fetch_assoc($group_list_result)) {
  echo "<input type=\"checkbox\" name=\"distro_{$row['group_name']}\"> {$row['group_name']}";
 }
?>

Pretty simple. I might have some syntax errors in there, but in my code they don’t exist, because it works fine.

So what I need to do, is run another query that returns ONLY the names of the groups that the employee belongs to:

SELECT group.group_name 
FROM group JOIN employee2group ON group.group_id = employee2group.group_id 
WHERE employee2group.employee_id ='{$_GET['employee_id']}'

Then, I need to compare the two queries, and output a normal check box when there isn’t a match, and output a checked check box when there is a match.

I tried doing a while statement that set $row = query1 and $row2 = query2, and compare the $row and $row2 values, but then it only returned instances where both queries had results, instead of all of them.

I hope this makes sense, I’ve been trolling the internet for a while, and haven’t found anything that pertains to my problem.

Thanks for reading!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:08:19+00:00Added an answer on May 18, 2026 at 4:08 am

    Two solutions :

    1 : Get a array of the groupIds that user is a member of, then when looping through the group list. Check if the id is in that array with in_array, if it is dont display the check box

    2 : Do a left join on the employee2group table and check if the value = null or not, if its null display the check box.

    —

    Off question topic but you should also look at using bound paramaters rather than just including them inthe sql statement like that, leaves it open to sql injection otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my toy setup. I have 3 tables. One table is a guest list
So here's the setup. I have two tables: CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)
Here's the setup: I have several tables that hold information for data objects which
Here is my table: id int(11) name varchar(255) description text highest_bidder int(11) value varchar(255)
Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20)
Here is my table | | Name | Vert | Horz | Area |
Here's the DB setup of 3 tables: Template ----------- TemplateId (Pk Identity) Name Example
With a table setup with the following fields: SKU, EVENTSTARTDATE, EVENTENDDATE, PRICE, (...etc...) and
All right, here's the setup: I have a table in a form whose contents
First, here are some scripts to setup the tables and background. CREATE TABLE TEST_P

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.