Hi this might be a very general question but i am open to all suggestions. I am using php, mysql and javascript in my code. How can i manage to find which tweet my client want me to remove? I mean if a delete button near the tweet is pressed how can i determine that remove button is associated with that tweet? I tried this but i couldn't get it going and i don't know what the problem is. Any suggestions?
Thank you
$sql = "select * from $user";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {?>
<div style="border-style:solid;
border-color:black;
border-width:3px;
position:relative;
margin-left: auto ;
margin-right: auto;
width:500px;
margin-bottom:5px;
margin-top:5px;
data-tweet="<?php echo $row['tweetid']; ?>
">
<?php echo $row['tweet'];?>
<input type="submit" name="delete" value="Delete" onclick="deletetweet()">
<script type="text/javascript">
function deletetweet(){
var twtid = this.getAttribute("data-tweet");
$.ajax({
type:"POST",
url: "deletefollower.php",
data: { twtid : twtid }
});
}
</script>
</div>
And php file
<?php
start_session();
include 'connection.php';
$user =$_SESSION["myusername"];
if(isset($_POST['twtid']))
{
$uid = $_POST['twtid'];
$sql="DELETE FROM $user WHERE tweetid='$uid'";
}
?>
Put the ID in a data attribute:
<div style="border-style:solid;
border-color:black;
border-width:3px;
position:relative;
margin-left: auto ;
margin-right: auto;
width:500px;
margin-bottom:5px;
margin-top:5px;"
data-tweet="<?php echo $row['tweet_id']; ?>">
Then your event handler can access this.getAttribute("data-tweet")
to get the tweet ID.