但让我们从开始说话。我正在创建类似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