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

时间:2015-04-09 12:35:49

标签: php html

我遇到的情况是我想点击链接并根据$ id获取数据。我能够做到这一点但我的问题是我希望结果显示在同一页面上而不是重定向到另一个页面

$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>";


		}

有没有办法可以避免重定向到“abstract.php”?

1 个答案:

答案 0 :(得分:2)

你可以使用javascript&amp; 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>

这样就可以了。 :)