-1

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>" . "\r\n" . $author . "</br>" . "\r\n" . "<u>" . $journal . "</u>" . "&nbsp" . $month . "\r\n" . "&nbsp" . $year . "\r\n" . "</br>" . "</br>";


  }

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

Jemshit
  • 9,501
  • 5
  • 69
  • 106
Maina Mailu
  • 73
  • 3
  • 13

1 Answers1

2

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. :)

Marko Šutija
  • 345
  • 3
  • 9