nethken nethken - 3 months ago 6x
jQuery Question

Pass data to the twitter modal

Hello i want to pass my

to the twitter modal. But im getting a wrong data Can someone give me ideas on how to pass a data to the modal?

i delete the news with news_id "29"
enter image description here

and the deleted data is news with news_id "28"
enter image description here

here is my code.

<div class="container">
<table class="table table-bordered" >
<th width="60">ID</th>
<th width="200">News Title</th>
<th width="150">Date Posted</th>
<th width="200">Image</th>
<th width="200">Action</th>

$stmt = mysqli_prepare($con, "SELECT * FROM news ORDER BY news_id");
$result = mysqli_stmt_get_result($stmt);
while($row = mysqli_fetch_array($result)){
<td><?php echo $row['news_id']; ?></td>
<td><?php echo $row['news_title']; ?></td>
<td><?php echo $row['news_date']; ?></td>
<td><?php echo $row['news_content']; ?></td>
<td><img style="height:150px; width:200px;" src="<?php echo $row['news_image']; ?>" ></td>
<a class='btn btn-info left-margin' href="edit2.php?newsid=<?php echo $row['news_id'];?>" ><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a class='btn btn-danger delete-object' data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-remove"></span> Delete</a>

<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
Are you sure you want to delete this?
<div class="modal-footer">
<a class='btn btn-danger left-margin' href="delete.php?newsid=<?php echo $row['news_id'];?>" >Yes</a>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>


here is my delete.php

$newsid = $_GET['newsid'];

$stmt = mysqli_prepare($con, "DELETE FROM news WHERE news_id = ?");
mysqli_stmt_bind_param($stmt, "s", $newsid);
header('location: edit.php');


The error resides in the way you declare your modals.

Your first delete button for news_id 28 opens the modal with the id #myModal, but so does the second button for news_id 29, which opens the first modal with id #myModal, being the modal for news_id 28.

Proposed solution: Add the ID to the modal.

<a class='btn btn-danger delete-object' data-toggle="modal" data-target="#modal<?php echo $row['news_id'];?>"><span class="glyphicon glyphicon-remove"></span> Delete</a>


<div class="modal fade" id="modal<?php echo $row['news_id'];?>" role="dialog" aria-labelledby="myModalLabel">

should fix it.