我正在试着做一个问答网页。我通过PHP从数据库获取数据,如下所示:

现在,我如何让每个数据都可以点击,这样在点击特定问题后,它将打开一个模式或一个新页面,其中包含被点击问题的数据。
我的代码是:
<?php
//Start to show '...' after 200 words.
function limited_echo($x, $length){
if(strlen($x)<=$length){
echo $x;}
else{
$y=substr($x,0,$length) . '...';
echo $y;}}
//End Here
//Main Code
include_once 'inc/connection.php';
$record= "SELECT * FROM questions";
$getdata = mysqli_query($link,$record);
if(! $getdata ) {
die('Could not get data');
}
while($row = mysqli_fetch_array($getdata)){
?>
<div class="section">
<h1><?php echo "{$row['title']}"; ?></h1>
<p><?php limited_echo($row['description'], 200); ?></p>
</div>
<?php
}
?>希望,这些信息就足够了。如果还需要什么,请让我知道。
发布于 2016-07-21 07:04:06
Since HTML5您可以使用<a>使<div>标记可链接。
<a href="[url here]">
<div class="section">
<h1><?php echo "{$row['title']}"; ?></h1>
<p><?php limited_echo($row['description'], 200); ?></p>
</div>
</a>对于它所链接的URL,拥有每个帖子链接到的ID将是很有用的,并且在该页面上使用该ID将需要在数据库中查找完整的帖子信息。
www.example.com/post.php?id=5 //post with the id 5
然后使用$_GET['post']变量在数据库中查找帖子。(警告:在执行查找或may end up with an SQL injection attack时,请确保转义此变量。)
https://stackoverflow.com/questions/38491812
复制相似问题