0
 <select class="form-control" name="brid">
                      <option value="" disabled selected="selected">Choose Branch</option>
                      <option value="All">All</option>

<?php 
    require_once '../db/db.php';

    $select = $conn->query("SELECT * FROM branches where access = 'User' or access = 'USER' ");

    while($row = mysqli_fetch_assoc($select)) {

            echo "<option value='".$row['brid']."'>".$row['brid']."</option>";
    }
?>
     </select>

This is my code for selecting branches, all i want is when i select all value. All the rows in branches table is having a same task.

<?php          
require '../db/db.php';

    $tkid = $_POST['tkid'];
    $brid = $_POST['brid'];
    $sdate = $_POST['sdate'];
    $edate = $_POST['ddate'];
    $tkname = $_POST['tkname'];
    $tkdesc = $_POST['tkdesc'];
    $noteby = $_POST['noteby'];

        $select = $conn->query("SELECT * FROM TASK WHERE tkid = '$tkid'");
        $count = mysqli_num_rows($select);

        if ($count == 0) {

        $query = $conn->query("INSERT INTO TASK (brid,tkid,tkname,tkdesc,sdate,edate,ntby) 
            VALUES ('$brid','$tkid','$tkname','$tkdesc','$sdate','$edate','$noteby')");

            echo "<script>alert('The task is successfully created');</script>";
            echo "<script>window.location.assign('../load/atask.php')</script>";
        }

        else{

            echo "<script>alert('The task is already created');</script>";
            echo "<script>window.location.assign('../load/atask.php')</script>";

        }


?>

This is my insertfile all i want is to insert the data to all user fetched to branches table

JYoThI
  • 11,977
  • 1
  • 11
  • 26
James
  • 1
  • 6
  • 2
    I am not sure that I understand the question, but I *think* that you want to check if the user selected `ALL` and,if they did, don't have any `WHERE` clause on your `SELECT` - just `$select = $conn->query("SELECT * FROM branches");` – Mawg says reinstate Monica Aug 24 '17 at 06:46
  • if you mean to say multiple selection, then need to add `multiple` attribute as well as name should be array so you can get your selected values – Jigar Shah Aug 24 '17 at 06:50
  • yes, when i select All in dropdown. I want to insert the same task to all branches – James Aug 24 '17 at 06:55
  • Possible duplicate of [How to get multiple selected values of select box in php?](https://stackoverflow.com/questions/2407284/how-to-get-multiple-selected-values-of-select-box-in-php) – Jigar Shah Aug 24 '17 at 07:07
  • is it posible when i choose All it insert to all branches that is registered to the branches table – James Aug 24 '17 at 07:10

2 Answers2

0

run the request through a foreach loop, in the loop do the insert based on the fields from the request that are row names.

Adnan
  • 1
  • 1
0

I already found the answer thanks for the suggestion guys

        $arr_br = array();

        $selectagain = "SELECT * FROM branches where access = 'User' ";

        if($countrows = mysqli_query($conn, $selectagain)){

            while($row = mysqli_fetch_assoc($countrows)){
                $arr_br[count($arr_br)] = $row["brid"];
            }
        }

        for($x = 0; $x < count($arr_br); $x++) {
            $insert = $conn->query("INSERT INTO TASK(brid,tkid,tkname,tkdesc,sdate,edate,ntby) VALUES ('".$arr_br[$x]."',(SELECT CONCAT('Pandayan-Task #',(count(id) + 1 )) from TASK as tkid), '$tkname', '$tkdesc', '$sdate', '$edate', '$noteby') ");

        echo "<script>alert('The task is successfully created');</script>";
        echo "<script>window.location.assign('../load/atask.php')</script>";

        }

    }

    else {

    $select = $conn->query("SELECT * FROM TASK WHERE tkid = '$tkid'");
    $count = mysqli_num_rows($select);

    if ($count == 0) {

    $query = $conn->query("INSERT INTO TASK (brid,tkid,tkname,tkdesc,sdate,edate,ntby) 
        VALUES ('$brid','$tkid','$tkname','$tkdesc','$sdate','$edate','$noteby')");

        echo "<script>alert('The task is successfully created');</script>";
        echo "<script>window.location.assign('../load/atask.php')</script>";
    }

    else{

        echo "<script>alert('The task is already created');</script>";
        echo "<script>window.location.assign('../load/atask.php')</script>";

    }


    }
James
  • 1
  • 6