0
I have a Grid where I click the edit button and it should bring BD data in a Modal but it is not working.
Follow the code.
Knob
Obs. (The Button is bringing the id)
<a href="#my_modal" data-toggle="modal" data-fornecedor-id="<?php echo $rowPedido->id; ?>" >
Div to Return Data
<div class="fetched-data"></div>
Jquery
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
var rowid = $(e.relatedTarget).data('fornecedor-id');
$.ajax({
type : 'post',
url : 'readDetails.php', //Here you will fetch records
data : 'rowid='+ rowid, //Pass $id
success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
}
});
});
});
Php (readDetails.php)
$conn = new PDO('**dados da conexão**');
//Include database connection
if($_POST['rowid']) {
$id = $_POST['rowid']; //escape string
// Run the Query
// Fetch Records
// Echo the data you want to show in modal
$sql = $conn->prepare( "SELECT * FROM Pedidos WHERE id = $id");
$sql->execute();
$result = $sql->fetch(PDO::FETCH_ASSOC);
}
An error is already on the line
var rowid = $(e.relatedTarget).data('fornecedor-id');
where the attributefornecedor-id
does not exist, so changefornecedor-id
forid
only. This is an indication, the others depend on the rest of your code that is not available to better analyze.– William Novak
Opa thanks for the touch actually the provider-id was a test I was doing and forgot to take out I believe the problem is in the readDetails.php returns nothing
– Shaolin Fantastic
Put a
print_r($result)
in the readDetails.php to see what returns.– William Novak
Nothing returns a blank screen
– Shaolin Fantastic
When you say that the button is bringing the id is because the attribute is being filled correctly in HTML or because in Javascript it is being correctly read? My question is whether after the line
var rowid = ....
the value is in the variablerowid
.– Waldir J. Pereira Junior
It is because it is being filled in correctly in HTML.
– Shaolin Fantastic