0

Hi all,
I am having a projectassign page,in that page i am having a dropdown box in which names of the projects are present.I am getting that project names from database. Below that list of users with checkbox are present.
So i can select a project from dropdown and check two users and click submit button,those two users will be assigned to that project.
Every this till this is fine.
Here is my question.Now when i select the same project from dropdown then it should show the two users as checked.and remaining users as unchecked. So anyone can help me please....

3
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by niths
0

Well, you are somehow assigning the two (or whatever you selected) users to the project right? Now, the only thing you should do is (when you are retrieving the user list in order to build the list of checkboxes), check wheather a user is assigned to a project allready, and if the user is, you only have to add "checked" at the end of the checkbox tag.

<input type="checkbox" name="something" value="something">

becomes

<input type="checkbox" name="something" value="something" CHECKED>
0

the users list is cuming from database. so if it is static then ur code is k.but hw can i do that for dynamic. wat i need is when i select a project from dropdown i should get the users as checked if they are assigned. so i think u understood my problem..

0

You mean you want to update the list as soon as another project is selected?

If so, you have 2 options: Either you (automatically if you don't want to have a confirmation button) submit a forum when the dropdown list is changed or you make a AJAX request (which is basically the same really) to update the contents of the current page.

0

what i mean is when i select a different projectname from dropdown(if that project is new one) then it should show all users unchecked(here each user is having one check box). If he selects the other project from dropdown and there are some users assigned to that project then those users check box should be as checked.

0

I just said that. But I don't understand what you still need. You already have a list of users and projects in your database, so you can make the checkboxes checked/unchecked like I said in the first post. The only thing you need to do is refresh the page when the value of the dropdown list changes.

You can add an onchange event to the list and let it refresh a form that submits to the same page if you want to keep things simple.

0
<table align="center">
    <tr>
        <td style="color: navy;">Projectassign</td>
        <td><select id="prolist" name="projectassign">
        <option  value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?> 
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px" bordercolor="red">
    <tr>
        <th></th>
        <th style="color: navy;">Userid</th>
        <th style="color: navy;">Username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>

this is my code. can u please see this.

0

I don't know how you set up your database, but you'll need to have some sort of list of users that are assigned to the project. You probably need to run a second MySQL query fetching the userid's of the users that are assigned to the project.

Then, at line 23, you'll need to add CHECKED to the end of the <input> tag if the userid belongs to a user that is assigned to the current project.

0
$sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$projectname\">".$projectname.'</option>';
    }
    $num=mysql_num_rows($result);
    $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2); 
    ?>

this is my sql queries.

0

First, i think your value in select-options must be a projecIds.

#
while ($row=mysql_fetch_array($result)) {

$id=$row["projectid"];
$projectname=$row["projectname"];
$options.="<option value=\"$id\">".$projectname.'</option>';

}

Second, when you create users check-box you have to do verification about that the user whether assign to current selected option(project) or not. This you can do with compare between userprojecId and current selected projectId. If user belong of current selected project, you just add the CHECKED tag to checkBoks Html.

<input type="checkbox" name="something" value="something" CHECKED>

Thirdly, you want selecting users every time when you change the current selected project, you have to do Ajax request to php script or just Submit. There you must to select users who belong to new selected project. After that you had their IDs, with little help of JavaScript you can change checked-user.
Other way to do this is just to reload the page on "onchange event" of slectbox.

0

Now i am able to get the userid's who are assigned to the project which i had selected in the drop down box and click submit button.
Below is the query to get userids.

$sql3="select userid from projectassign where projectassign='$projectassign'";
     mysql_error();
    $result3=mysql_query($sql3);
    $num1=mysql_num_rows($result3);
    $i=0;
    while ($i < $num1)
    {
        $f1=mysql_result($result3,$i,"userid");
        echo $f1;
        $i++; 
    }

so now wat i need is without clicking on submit button immediately after selecting the projectname in the dropdown box i should get the userids.so can any one please....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.