est. sorun çözüldüyse ne mutlu iyi çalışnalar kolay gelsin 😊
Şimdi farklı bir sıkıntı oluştu. Verileri ve Buttonları döngü içinde çekerek oluşturuyorum. Şu an yaptığımız sisteme göre tüm butonların id' si "düzenle" oldu. Ajax post işlemini buton id sine göre yaptığımız için tüm modallarda aynı çıkıyor çakışıyor.
Buton id değerinide veritabanından çeksem değişken olsa bu seferde ajax fonksiyonu içindede bu buton id değişkenini tanımlamak gerekecek.
Ayrıca ajax scripti içinde modal ismi olmadığı için başka modallarla da çakışıyor
Bu sorunu nasıl çözebiliriz?
Benim Kodum;
<?php
include("veritabani.php");
?>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="Tr">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link href="hummingbird-treeview.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<title>Kayıtlar</title>
</head>
<body>
<div class="container">
ÜRÜN EKLE - DÜZENLE
<div class="kolon6">
<button onClick="location.href='rapor.php'" type="button">ÜRÜN Ekle</button>
</div>
<br/>
<div class="kolon5">
<table border="1">
<tr>
<td colspan="4" align="center">ÜRÜNLER</td>
</tr>
<tr>
<td width="25%">ADI</td>
<td width="25%">MODELİ</td>
<td width="25%">ÜCRET</td>
<td width="25%">KONTROL</td>
</tr>
<?php
$sorgu = $baglanti->query("SELECT * FROM yeni where kod=4 ORDER BY adi asc");
if ($baglanti->errno > 0) {
die("<b>Sorgu Hatası:</b> " . $baglanti->error);
}
while ($cikti = $sorgu->fetch_array()) {
?>
<tr>
<td><?php echo $cikti["adi"]; ?></td>
<td><?php echo $cikti["aciklama"]; ?></td>
<td><?php echo $cikti["ucret"]; ?></td>
<td><button type="button" id="duzenle" class="btn btn-primary btn-sm" data-id="<?php echo $cikti["id"]; ?>" data-toggle="modal" data-target="#myModal">Düzenle</button></td>
</tr>
<?php
}
$sorgu->close();
$baglanti->close();
?>
</table>
</div>
<!-- Modal -->
<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">Ram Raporu Güncelleme</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
$("#duzenle").click(function(e) {
var id= $(this).attr("data-id");
$.ajax({
type: "POST",
url: "post.php",
data: {
id: id,
},
success: function(result) {
$('.modal-body').html(result);
},
});
});
</script>
</body>
</html>
Şimdi farklı bir sıkıntı oluştu. Verileri ve Buttonları döngü içinde çekerek oluşturuyorum. Şu an yaptığımız sisteme göre tüm butonların id' si "düzenle" oldu. Ajax post işlemini buton id sine göre yaptığımız için tüm modallarda aynı çıkıyor çakışıyor.
Buton id değerinide veritabanından çeksem değişken olsa bu seferde ajax fonksiyonu içindede bu buton id değişkenini tanımlamak gerekecek.
Ayrıca ajax scripti içinde modal ismi olmadığı için başka modallarla da çakışıyor
Bu sorunu nasıl çözebiliriz?
Benim Kodum;
<?php
include("veritabani.php");
?>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="Tr">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link href="hummingbird-treeview.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<title>Kayıtlar</title>
</head>
<body>
<div class="container">
ÜRÜN EKLE - DÜZENLE
<div class="kolon6">
<button onClick="location.href='rapor.php'" type="button">ÜRÜN Ekle</button>
</div>
<br/>
<div class="kolon5">
<table border="1">
<tr>
<td colspan="4" align="center">ÜRÜNLER</td>
</tr>
<tr>
<td width="25%">ADI</td>
<td width="25%">MODELİ</td>
<td width="25%">ÜCRET</td>
<td width="25%">KONTROL</td>
</tr>
<?php
$sorgu = $baglanti->query("SELECT * FROM yeni where kod=4 ORDER BY adi asc");
if ($baglanti->errno > 0) {
die("<b>Sorgu Hatası:</b> " . $baglanti->error);
}
while ($cikti = $sorgu->fetch_array()) {
?>
<tr>
<td><?php echo $cikti["adi"]; ?></td>
<td><?php echo $cikti["aciklama"]; ?></td>
<td><?php echo $cikti["ucret"]; ?></td>
<td><button type="button" id="duzenle" class="btn btn-primary btn-sm" data-id="<?php echo $cikti["id"]; ?>" data-toggle="modal" data-target="#myModal">Düzenle</button></td>
</tr>
<?php
}
$sorgu->close();
$baglanti->close();
?>
</table>
</div>
<!-- Modal -->
<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">Ram Raporu Güncelleme</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
$("#duzenle").click(function(e) {
var id= $(this).attr("data-id");
$.ajax({
type: "POST",
url: "post.php",
data: {
id: id,
},
success: function(result) {
$('.modal-body').html(result);
},
});
});
</script>
</body>
</html>
Sorunu mu verdiğiniz script kodunu aşağıdaki şekilde değiştirerek çözdüm. Teşekkürler.
<script>
$('#myModal').on('show.bs.modal', function(e) {
//get data-id attribute of the clicked element
var id = $(e.relatedTarget).data('id');
$.ajax({
type: "POST",
url: "post.php",
data: {
id: id,
},
success: function(result) {
$('.modal-body').html(result);
},
});
});
</script>