jeudi 13 juillet 2017

How to run the same query for multiple users whose ID is stored in an array?

I'm making a task management system, working on the admin part now. I want the admin to be able to assign tasks to one user/multiple users at once, so let's say I run a php code to store the checkboxed values into an array. How do I insert the task given into the array?

This is the html part :

<form action="" method="POST">
            <?php
                $query = mysqli_query($con, "SELECT name, teamid FROM team order by teamid asc");
                $row = mysqli_fetch_array($query) or die(mysqli_error($con));
                while($row = mysqli_fetch_array($query))
                {
                    $tna = $row['name'];
                    $tid = $row['teamid'];
                echo '
                    <input type="checkbox" name="selcheck[]" value="'.$tid.'" />
                    <label>'.$tna.'</label>
                    '; } ?>
            <br />
            <textarea name="tetaskmsg" style="width: 60%; min-height: 100px;" placeholder="Enter the task to be given here."></textarea><br />

            <input type="submit" name="tetaskbtn" value="Assign" />
                </form>

And this is the php part, which I can't figure out,

if(isset($_POST['tetaskbtn']))
{
    $selteams = $_REQUEST['selcheck'];
    $b = implode(", ", $selteams);
    $query = "INSERT into user(task) VALUES('true') WHERE userId='$b' ";
    echo $b;
}

$b is obviously a string value, so I know it wouldn't compare with the user id which is an INT. I know that, my question is how do I do it?

Aucun commentaire:

Enregistrer un commentaire