PHP通过单击Href链接并在相同的URL中显示结果从MySQL获取数据

PHP通过单击Href链接并在相同的URL中显示结果从MySQL获取数据

问题描述:

i'm faced with a situation where i want to click on a link and get data based on the $id. I'm able to do this but my problem is that i want the results to show on the same page not redirect to another page

$con = dbConnect();
    $sql = $con->prepare("SELECT manuscript_id,authors,month,year,title,journal,pubmed_link FROM manuscript WHERE title like '%$term%'");
        $sql->execute();
        $sql->setFetchMode(PDO::FETCH_ASSOC);
//
        if ($sql->fetch() == 0){
        echo ('<h2>SORRY! No results found</h2>');
            }


        else {
        
        $x=1;       
        while ($row = $sql->fetch()){//three
                $manuscript_id = $row ['manuscript_id'];
                $author = $row ['authors'];
                $month = $row ['month'];
                $year = $row ['year'];
                $title = $row['title'];
                $journal = $row ['journal'];
                $pubmed_link = $row ['pubmed_link'];
        
        
        echo $x++;
        echo "<input type = 'checkbox' id='list' value='list'>";
        echo ('<a href="abstract.php?manuscript_id=' . $manuscript_id . '">' . $title . '</a>') . "</br>" . "
" . $author . "</br>" . "
" . "<u>" . $journal . "</u>" . "&nbsp" . $month . "
" . "&nbsp" . $year . "
" . "</br>" . "</br>";


        }

Is there a way i can avoid redirecting to "abstract.php"?

</div>

You can use javascript & jQuery for that.

<a href="abstract.php?manuscript_id=' . $manuscript_id . '" class="clickMe">
<div id="results"></div>

<script type="text/javascript">
$('a.clickMe').click(function(e){
   // Stop default click action in browser
   e.preventDefault();

   // Make ajax call
   $.ajax($(e.target).attr("href"), {
     cache:false,
     success:function(data){
         $("#results").html(data);
     }
   });
})
</script>

That will do the trick. :)