I am having difficulties getting this part of my html/php page working, everything else works fine except the modal.
I am using Bootstrap 4.3.1 in the template I am using, i have followed a lot of other post's on SOF but none seem to work. The following code is where it gets called from
<a data-toggle="modal" href="vehicles.php#vehicle_delete_<? echo $row->id;?>" class="btn btn-light"><span class="fa fa-trash"></span></a>
and the modal section;
<? if ($_SESSION['admin_level']>=3) { ?>
<div class="modal fade" id="vehicle_delete_<? echo $row->id;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><span class="fa fa-pencil"></span> Delete <? echo $row->classname;?></h4>
</div>
<div class="modal-body">
<div class="form-group">
<form method="post" action="vehicles.php#vehicles_delete_<? echo $row->id;?>" role="form">
<input type="hidden" name="type" value="delete" />
<input type="hidden" name="id" value="<? echo $row->id;?>" />
<p>Do you really want to delete the Vehicle "<? echo $row->classname;?>" from the User <? echo $row->name;?>?</p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-light" data-dismiss="modal" type="reset">Cancel</button>
<button class="btn btn-light" type="submit">Delete Vehicle</button>
</form>
</div>
</div>
</div>
</div>
<? } ?>
I have the same exact code on an version v3.3.5 of Bootstrap and it works quiet fine, but since upgrading to the version I am currently using in this template, it no longer works.
The following is the footer
<!-- Bootstrap core JavaScript-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- loader scripts -->
<script src="assets/js/jquery.loading-indicator.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Chart js -->
<script src="assets/plugins/Chart.js/Chart.min.js"></script>
<!-- Index js -->
<script src="assets/js/index.js"></script>
The following is the header
<!-- loader-->
<link href="assets/css/pace.min.css" rel="stylesheet"/>
<script src="assets/js/pace.min.js"></script>
<!--favicon-->
<link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
<!-- Vector CSS -->
<link href="assets/plugins/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet"/>
<!-- simplebar CSS-->
<link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet"/>
<!-- Bootstrap core CSS-->
<link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
<!-- animate CSS-->
<link href="assets/css/animate.css" rel="stylesheet" type="text/css"/>
<!-- Icons CSS-->
<link href="assets/css/icons.css" rel="stylesheet" type="text/css"/>
<!-- Sidebar CSS-->
<link href="assets/css/sidebar-menu.css" rel="stylesheet"/>
<!-- Custom Style-->
<link href="assets/css/app-style.css" rel="stylesheet"/>
Regards.
You shoud add data-target instead of href
from this to
<a data-toggle="modal" href="vehicles.php#vehicle_delete_<? echo $row->id;?>" class="btn btn-light"><span class="fa fa-trash"></span></a>
This
<a data-toggle="modal" href="" class="btn btn-light" data-target="#vehicle_delete_<? echo $row->id;?>"><span class="fa fa-trash"></span></a>
Then after you have to pass the URL to Delete vehicle button
Can you try to add data-target on the buttons?
<a data-toggle="modal" data-target="#vehicle_delete_<? echo $row->id;?>" class="btn btn-light"><span class="fa fa-trash"></span></a>
Could be Bootstrap 3 prevents the default behavior on the href, but Bootstrap 4 doesn't.
Related
I have this modal:
<div class="container">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
And I would like to toggle it when I am executing some PHP code
if(//){
//toggle modal
}
What I have tried so far was setting a flag to true when function is executed and then in html I do this:
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
but it still doesn't work. Any one knows whats going on here?
EDIT: all the plugins I am loading in the html header
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="../style.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
Because you have set jquery plugin twice, it might be getting difficult. So, you have 2 options in my mind. First, you could move bootstrap plugin to the bottom and remove one of the jquery plugins. Just before body ends. like:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
Or, you could use:
$(document).ready(function(){
// Here goes yor code
});
As you import bootstrap, and again added jquery plugin. You have to use document.ready to insure all files are loaded, then we will use the function.
*Note:- You might have to move the jquery table plugin after bootstrap too, if you move the bootstrap.js. I am not sure about that, cos I haven't use that plugin yet.
Edited to include proper format for more readable and understandable code. Also fixed to where the proper placement for ideal performance with the Javascript files are added to the ending of the <html> tag opposed to the <head> tag
<!DOCTYPE html>
<html>
<head>
<title>ROWLANDS SHOP</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta name="viewport" content="width=device-width, initial-scale=1, user-
scalable=no">
</head>
<body>
<div class="modal fade details-1" id="details-modal" tabindex="-1"
role="dialog" aria-labelledby="details-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" onclick="closeModal()"
aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" class="text-center"><?=
$product['title'];?></h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div class="center-block"></div>
<img src="<?= $product['image'];?>" alt="<?
=$product['title'];?>" class="details img-responsive">
</div>
<div class="col-sm-6">
<h4>Details</h4>
<p><?= $product['description'];?></p>
<hr>
<p>price: $<?= $product['price'];?></p>
<p>Brand:<?= $brand['brand']; ?></p>
<form action="add_cart.php" method="post">
<div class="form-group">
<div class="col-xs-3">
<label for="quantity">Quaantity:</label>
<input type="text" class="form-control" id="quantity"
name="quantity">
</div>
</div>
<div class="form-group">
<label for="size">Size:</label>
<select name="size" id="size" class="form-control">
</select>
<option vaue=""></option>
<?php foreach($size_array as $string){
$string_array = explode(':', $string);
$size = $string_array[0];
$quantity = $string_array[1];
echo '<option
vaue="'.$size.'">'.$size.'('.$quantity' Avaliable)</option>';
} ?>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default"
onclick="close_modal();">Close</button>
<button class="btn btn-warning" type="submit"
class="glyphicon glyphicon-shopping-cart"><span>Add to Cart</span></button>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</html>
Is other styles from Bootstrap Working? And could you please give more information such as where you are including the Javascript and Popper.js? I'm sorry but there is so much little information that is given that it could simply just be it's not loading Bootstrap into the project. Please revise and add some more information that can possibly help us debug this for you.
Here is the boilerplate for a modal in bootstrap and a trigger with a button. Take this and see if this works for you and then you can re-add the other components you had to it. If this doesn't open up a modal then it might just be a loading problem with Bootstrap.js.
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Here is the link to the official Bootstrap Documentation. https://getbootstrap.com/docs/4.4/components/modal/
Also Please note that the code you have provided is missing the required Popper.js file. Please Add this code above the ending <html> tag.
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
If you simply don't want to use the online versions of the Bootstrap.js, Jquery.js, or Popper.js Here are the websites where you can find them and download them to easily extract to your project.
Jquery Code Uncompressed: https://code.jquery.com/jquery-3.4.1.js - Just save this into a file called jquery.js and include it with a script tag
Bootstrap.js: Can be downloaded from the official Bootstrap Website - https://www.getbootstrap.com
Popper.js: https://popper.js.org/ - Can be downloaded here
Also please read the StackOverflow Guide to asking a good question you can find here at: https://stackoverflow.com/help/how-to-ask
I have a laravel datatable the following:
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.16/datatables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/dt-1.10.16/datatables.min.css"/>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.1/css/responsive.bootstrap.min.css"/>
</head>
This is the table:
<td><button
type="button"
class="btn btn-primary btn-lg"
data-toggle="modal"
data-target="#favoritesModal">
Add to Favorites
</button></td>
and here I have created the modal:
<div class="modal fade" id="favoritesModal"
tabindex="-1" role="dialog"
aria-labelledby="favoritesModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title"
id="favoritesModalLabel">The Sun Also Rises</h4>
</div>
<div class="modal-body">
<p>
Please confirm you would like to add
<b><span id="fav-title">The Sun Also Rises</span></b>
to your favorites list.
</p>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-default"
data-dismiss="modal">Close</button>
<span class="pull-right">
<button type="button" class="btn btn-primary">
Add to Favorites
</button>
</span>
</div>
</div>
</div>
</div>
Can anyone please help me how do I implement this modal in a datatable row?
Basically I want everytime the user clicks a button show Image to open a modal with the image inside
Thanks in advance
Probably easiest if you add a unique class (say... 'imageButton') as well as a data-image-id to the button to identify which image you want. If you want individual title, you may wish to add a data-img-title on the same button.
So - sort of like this:
<td><button
type="button"
class="btn btn-primary btn-lg imageButton"
data-toggle="modal"
data-img-title ="{{$looped->title}}"
data-img-id = "{{$looped->id}}"
data-target="#favoritesModal">
Add to Favorites
</button></td>
Then, some jquery AJAX to get the image data from your controller and then place that HTML inside the modal. Something like this:
$('.imageButton').on('click', function () {
var imgTitle = $(this).data('img-title');
var imgId = $(this).data('img-id');
$.ajax({
url: "{{url('url_for_your_image_returning_controller_method)}}" + "/" + imgId,
type: "GET",
success: function (h) {
$(".modal-title").text(imgTitle);
$(".modal-body").html(h);
$('#modal').modal();
},
error: function () {
swal("Error", "Unable to bring up the creation dialog.", "error");
}
})
});
Depending on what you are sending through that would work. You can also chose to create an image tag, and send through the new src instead of photo data something like this if you want to show thumbnails as well:
<img id="modalImage" src="{{url('images')."/".(isset($image->thumb)?$image->thumb:$image->image)}}"
class="picToModal">
Then replace the src within the $("#modalImage") element with your new source and trigger. There are lots of options and branches, and you'll need to re-work to suit, but this should get you started.
i'm using cakePHP3 with AdminLTE theme, i want my login page rendered with pure html from .ctp with no additional theme view generated by controller, is there a way to accomplish that? i've already tried $this->viewBuilder()->layout(false) in my action function, but it didn't work
Create a new layout to be used for the login page, let's call the layout 'loginLayout'. Below is a sample code based on maiconpinto adminlte plugin. If you are not using the plugin, make sure you indicate the right path for your CSS and script files.
<?php use Cake\Core\Configure; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo Configure::read('Theme.title'); ?></title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<?php echo $this->Html->css('AdminLTE./bootstrap/css/bootstrap.min'); ?>
<!-- iCheck -->
<?php echo $this->Html->css('AdminLTE./plugins/iCheck/all.css'); ?>
<!-- Font Awesome -->
<link rel="stylesheet" href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'>
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<?php echo $this->Html->css('AdminLTE.AdminLTE.min'); ?>
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<?php echo $this->Html->css('AdminLTE.skins/skin-'. Configure::read('Theme.skin') .'.min'); ?>
<?php echo $this->fetch('css'); ?>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition login-page">
<?php echo $this->Flash->render(); ?>
<?php echo $this->Flash->render('auth'); ?>
<?php echo $this->fetch('content'); ?>
<!-- jQuery -->
<?php echo $this->Html->script('https://code.jquery.com/jquery-3.2.1.min.js'); ?>
<!-- Bootstrap 3.3.5 -->
<?php echo $this->Html->script('AdminLTE./bootstrap/js/bootstrap.min'); ?>
<!-- iCheck -->
<?php echo $this->Html->script('AdminLTE./plugins/iCheck/icheck.min.js'); ?>
<!-- AdminLTE App -->
<?php echo $this->Html->script('AdminLTE./js/app.min'); ?>
<!-- AdminLTE for demo purposes -->
<?php echo $this->fetch('script'); ?>
<?php echo $this->fetch('scriptBottom'); ?>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$(".navbar .menu").slimscroll({
height: "200px",
alwaysVisible: false,
size: "3px"
}).css("width", "100%");
var a = $('a[href="<?php echo $this->request->webroot . $this->request->url ?>"]');
if (!a.parent().hasClass('treeview') && !a.parent().parent().hasClass('pagination')) {
a.parent().addClass('active').parents('.treeview').addClass('active');
}
});
</script>
</body>
</html>
On your .ctp file, indicate the layout to be used
<?php
$this->layout = 'loginLayout';
?>
<div class="login-box">
<div class="login-logo">
<b>Admin</b>LTE
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<form action="../../index2.html" method="post">
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
<div class="social-auth-links text-center">
<p>- OR -</p>
<a href="#" class="btn btn-block btn-social btn-facebook btn-flat"><i class="fa fa-facebook"></i> Sign in using
Facebook</a>
<a href="#" class="btn btn-block btn-social btn-google btn-flat"><i class="fa fa-google-plus"></i> Sign in using
Google+</a>
</div>
<!-- /.social-auth-links -->
I forgot my password<br>
Register a new membership
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
I'm having a hard time in this one. I want to add data to a column in my database.
If there is an existing type in the database, then it not going to add, and if not it is going to add. However, it seems that my $validate is always empty.
Thanks in Advance. I really Appreciate your Help Thanks again.
this my add_item_type.php
$newi = $_GET["newi"];
$dept = $_GET["dept"];
$connection = mysqli_connect("localhost","root","","fumc");
$sql = mysqli_query($connection," SELECT * FROM items WHERE type = '".$newi."' ");
while($data=mysql_fetch_array($sql)){
$validate = $data['department'];
}
if($validate=="")
{
}
else
{
mysqli_query($connection," INSERT INTO items (type,department)VALUES('".$newi."','".$dept."') ");
echo mysqli_affected_rows($connection);
}
?>
My database name is fumc, my table name is items and inside my table i have type And Department .... One of my type is keyboard and department is IT..
this is my main.php
<html>
<body>
<head>
<link rel="icon" type="image/png" href="fumc.png">
<link href="css123/bootstrap.min.css" rel="stylesheet">
<link href="css123/simple-sidebar.css" rel="stylesheet">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<input type="button" name="modal" value="Add Item Type" class="btn btn-primary" style="margin-left:100px;" data-toggle="modal" data-target="#myModal">
<center>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" style='top:0px;'>
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="width:400px;">
<div class="modal-header " style='background:#ddd;'>
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="font-family:Arial Black;color:green;"><center><b>ADD ITEM TYPE</b></center></h4>
</div>
<div class="modal-body">
<br>
<form action="#" method="post">
<input type='hidden' value='<?php echo $department?>'name ='dept' id='dept'>
<center>
<font class='text-success' ><b>NEW ITEM TYPE</b>
<input type='text' name ='newi' id='newi' style='margin-left:10px;border:1px solid gray;text-align:center;background:Transparent;'>
</font>
</center>
</div>
<br>
<div class="modal-footer" style='background:#ddd;'>
</form>
<button type="button" class="btn btn-info " name="add" id="add" >Add Item Type</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</center>
<script>
$(function(dd){
$("#modal").on("click",function(dd){
var dept = $("#dept").val();
var newi = $("#newi").val();
});
$("#add").on("click",function(tt){
var dept = $("#dept").val();
var newi = $("#newi").val();
$.get("add_item_type.php?newi="+newi+"&dept="+dept,function(values){
location.reload();
});
});
});
</script>
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="plugins/fastclick/fastclick.min.js"></script>
<script src="dist/js/app.min.js"></script>
<script src="dist/js/demo.js"></script>
</body>
</html>
Need help Please..! Thanks.
The easiest way to do this is to use MySQL's built in UNIQUE attribute. Set the department column of your database table to be unique, then you can use a query like this:
"INSERT IGNORE INTO items (type,department) VALUES ('".$newi."','".$dept."')"
This query will only insert a new row if the $dept value doesn't match any of the other values in the department column.