I have a div that uses some unique id from a mysql db that I have to pass to my javascript file so I could display results from another php script in a particular div with a specific id that corresponds to the one obtained from the db.
index page.
<div class="wrapper">
<?php
$query = mysqli_query($con, 'SELECT * FROM in_table limit 10 ');
while($result = mysqli_fetch_array($query)){ ?>
<img src= <?php echo $result['user_image_url']; ?> />
<?php
echo $result['msg'].'</br>';
echo '<a href="#'.$result['statusID'].'">More...</a></br>';
echo '<div id="'.$result['statusID'].'" class="rest" style="width: 400px; height: 100px;"></div>';
}
?>
The div is inside the while loop.
ajax.js
$('a').on('click', function(){
var hash = this.hash.replace('#','');
$.post('content.php', {id: hash}, function(data){
$('div#?????').html(data);
});
})
So how do I call that div inside?
content.php
<?php
include('ajax.php');
if (isset($_POST['id'])) {
$id = $_POST['id'];
}
$query = mysqli_query($con, "SELECT * FROM comments where statusID = '".$id."'");
while($row = mysqli_fetch_array($query)){
echo $row['message'].'</br>';
}
?>