Espero me puedan colaborar, necesito resolver este detalle,
estoy usando PHP "DataTable" y Bootstrap, donde me muestra todo los comentarios en general de la base de datos.
la idea es que al seleccionar un post.. me muestre solo los comentarios de ese dicho post,
la tabla "feedbacks" tiene el ID de la tabla "post" post_id
Se, me ocurre algo así, pero tampoco me resulto "myfeedback.php".
$query .= 'WHERE feedbacks_id = '".$_POST["post_id"]."' ';
Código Javascript:
Ver original
Esto carga la lista de comentarios <script> $(document).ready(function () { //........ var dataTable = $("#MyTablaFeedback").DataTable({ paging: true, processing: true, serverSide: true, order: [], info: false, ajax: { url: "myfeedback.php", type: "POST", }, columnDefs: [ { targets: [0, 1, 2], orderable: false, }, ], }); } </script>
MUESTRA TODO LOS COMENTARIOS "myfeedback.php"
Código PHP:
Ver original
<?php include_once 'conn.php'; function get_total_all_records() { include('conn.php'); $statement = $conexion->prepare("SELECT * FROM feedbacks"); $statement->execute(); $result = $statement->fetchAll(); return $statement->rowCount(); } $query = ''; $query .= "SELECT * FROM feedbacks "; { $query .= 'WHERE msg_feedbacks LIKE "%'.$_POST["search"]["value"].'%" '; // AQUI TRAER EL ID DEL COMENTARIO AL SELECCIONAR UN POST } { $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' '; } else { $query .= 'ORDER BY feedbacks_id DESC '; } if($_POST["length"] != -1) { $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $statement = $conexion->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $filtered_rows = $statement->rowCount(); foreach($result as $row) { $sub_array[] = $row["feedbacks_id"]; $sub_array[] = $row["msg_feedbacks"]; $sub_array[] = '<button type="button" name="viewFeedback" id="'.$row["feedbacks_id"].'" data-bs-dismiss="modal">VER COMENTARIO</button>'; $data[] = $sub_array; } "recordsTotal" => $filtered_rows, "recordsFiltered" => get_total_all_records(), "data" => $data ); ?>
MI LISTA DE PUBLICACIONES INDEX "fetch.php"
Código HTML:
Ver original
<div class="table-responsive-md"> <table class="table table-sm" id="MyTablaPOST"> <thead> <tr> </tr> </thead> </table> </div> <!-- My Modal de Feedback --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> </div> <div class="modal-body"> <!-- MI LISTA DE COMANTARIOS --> <div class="table-responsive-md"> <table class="table table-sm" id="MyTablaFeedback"> <thead> <tr> </tr> </thead> </table> </div> </div> <div class="modal-footer"> </div> </div> </div> </div>
fetch.php
Código PHP:
Ver original
<?php include_once 'conn.php'; { $statement = $conexion->prepare( "SELECT * FROM post WHERE post_id = '".$_POST["myid"]."' LIMIT 1" ); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { $output["post_id"] = $row["post_id"]; $output["title_mypost"] = $row["title_mypost"]; } } ?>
Código Javascript:
Ver original
Esto carga la lista de POST <script> //.... $(document).on("click", ".viewFeedback", function () { var myid = $(this).attr("id"); $.ajax({ url: "fetch.php", method: "POST", data: {myid: myid}, dataType: "json", success: function (data) { $("#post_id").val(data.post_id); $(".title_mypost").html("<span> " + data.title_mypost + " </span>"); $(".modal-title").text("Info..."); $("#myid").val(myid); $("#exampleModal").html(data); $("#exampleModalLabel").modal("show"); }, }); }); </script>