jeudi 12 février 2015

Retrieve checkbox state for certain users

I currently have some issues with how to solve this:


I have 2 tables: users and user_project. For each project (another table) users responsible for a project are stored in the user_project table.


Now I know how to format the inputted data, and store everything in the tables, but I'm stuck on editing a project. I'm stuck on how to check for each user wether they are linked to the project or not.


I should get a list like this:



user 1: [ ]
user 2: [ ]
user 3: [x]
user 4: [ ]
user 5: [x]
user 6: [ ]


This is what i have so for to get at least the users responsible:



$sql = mysql_query("SELECT * FROM `users`");

while ($row = mysql_fetch_array($sql)) {

$sql2 = mysql_query("SELECT * FROM `user_project` WHERE `uid` = '". $row['id'] ."' AND `pid` = '". $pid ."'");

while ($row2 = mysql_fetch_assoc($sql2)) {

if ($row['id'] == $row2['uid']) {

echo '<input name="assignee[]" type="checkbox" value="'. $row['id'] .'" checked="checked"><span class="smaller">'. $row['email'] .'</span><br>';

}

}

}




Aucun commentaire:

Enregistrer un commentaire