Home > Back-end >  Is that possible to seperate database if i insert more than 1 value?
Is that possible to seperate database if i insert more than 1 value?

Time:05-11

I want to separate database into two if i insert more than 1 value.In this picture, you can see 111111 and 111112 are inserted with "," in the same role. I want to make 111111 and 111112 as each line. In picture, you can see 111111 and 111112 are inserted with "," in the same role. I want to make 111111 and 111112 as each line. How can I make this? Below is my db.

    $seal_area = isset ($_GET['site'])? $_GET['site']:'';
$seal_qty = isset ($_GET['seal_qty'])? $_GET['seal_qty']:'';
$receive_by = isset ($_GET['stat'])? $_GET['stat']:'';
$seal_barcode = isset ($_GET['barcodeno'])? $_GET['barcodeno']:'';
$receive_id = isset ($_GET['secuid'])? $_GET['secuid']:'';
//$returnid = isset ($_GET['secuid'])? $_GET['secuid']:'';
$chk = isset ($_GET['chk'])? $_GET['chk']:'';
$admin_name = $_SESSION["loginname"];
if ($chk=='issue'){
    $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, issue_admin, receive_by, receive_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$receive_by','$receive_id')";
    $result1 = mysqli_query($conn,$sql1);
}
/*else if ($chk=='rtn'){
    $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, return_admin, return_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$returnid')";
    $result1 = mysqli_query($conn,$sql1);
}*/

flush();
mysqli_close($conn);

below is javascript.

    var barcodeno = document.translot.barcodeno.value;
      if (barcodeno == ""){
          alert("Please Insert Serial Numbers.")
          return false;
      }
      
  

  $('#filter').html(''); // to clear selection
  // lotid = $('#lotid').val().split('\n');
  var barcodeno = $('#barcodeno').val().trim();
  barcodeno = barcodeno.split('\n');
//checking duplicate barcodeno
    let barcodeno_array = []
    for(let i = 0;i < barcodeno.length; i  ){
        if(barcodeno_array.indexOf(barcodeno[i]) == -1){
            barcodeno_array.push(barcodeno[i])
        }
    }

CodePudding user response:

You can use PHP explode() function, this is used to string to array convert with comma separate after you loop your array in insert query.

if ($chk=='issue'){
 $barcodeArray = explode(",",$seal_barcode));
 foreach($barcodeArray as $value){
   $seal_barcode = $value;
   $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, issue_admin, receive_by, receive_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$receive_by','$receive_id')";
     $result1 = mysqli_query($conn,$sql1);
 }   
}
  • Related