但讓我們從開始說話。我正在創建類似wordpres博客索引頁面的網站(無法顯示圖片,因爲沒有足夠的聲望)。然後我點擊介紹文章中的read more鏈接,我想將該文章ID從數據庫保存到php sesions中。這是代碼。如何從數據庫設置ID到PHP會話鏈接點擊
while($row = mysqli_fetch_array($result))
{
echo '<div class="img">
<img src="img/smiley.gif" alt="Smiley face" width="250" height="250">
</div>';
echo "<h2>".$row['Name'] . "</h2> " ;
$string = strip_tags($row['Content']);
if (strlen($string) > 500) {
$stringCut = substr($string, 0, 500);
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="post.php?link=1">Read more</a>';
}
//echo $string;
if(isset($_GET['link']) /*you can validate the link here*/){
$_SESSION['link']= true;
}
echo $string;
echo "<br>";
echo '<div class="content dashboard clearfix"></div>';
echo '<hr>';
}
mysqli_close($con);
?>
所以我在index.php文件3篇介紹文章,我讀whant一個,所以我按更多(那我應該寫的文章編號,以會話),然後轉到其他網頁,都我想我應該從會話中獲取文章ID。我tryyng做與
if(isset($_GET['link'])){ /*you can validate the link here*/
$_SESSION['link']= true;
}
但它總是寫號5,從數據庫中的最後一個ID,所以我想我應該用AJAX或許,JavaScript的?也許有人能給我舉個例子嗎? 謝謝。
'如果(isset($ _ GET ['link'] && $ _GET ['link'] == $ row ['id'])'? – Sean