从url到php变量的id

时间:2019-03-13 17:52:53

标签: php mysql

我正面临下一个问题: 我每篇文章都有一个唯一的ID,但是我不知道如何在我的while循环的下一页中查询SELECT * FROM WHERE ask_id = x。现在应将href的ID(链接)添加到x中。实际上我只想将搜索栏中的ID转换为变量x

<?php
$statement = $pdo2->prepare("SELECT * FROM fragen ORDER BY fragen_date DESC");
$result = $statement->execute();
while($row = $statement->fetch()) {
        echo '<a class="kein" href="forum_forum.php?id='.$row['fragen_id'].'"><div class="forum"><div class="forum_Titel">' ,"Titel:  ".$row['fragen_title'].'</div>',
        "<br><br>",'<div class="forum_Subt  itel">', "Subtitel:  " .$row['fragen_subtitle'].'</div>',
        "<br><br>",'<div class="forum_Content">',"Text:  ".$row['fragen_content'].'</div>',
        "br><br>",'<div>'.$row['fragen_id'].'</div>',
        "<br><br>",'<div class="forum_Upload-date">',"Upload-Datum:  ".$row['fragen_date'].'</div>',
        '</div></a>';
    //the variable $chosen_one should get the value of the id   

    }               
?>

如您所见,它会正确生成网址的ID

<?php
$statement = $pdo2->prepare("SELECT * FROM fragen WHERE ");
$result = $statement->execute();
while($row = $statement->fetch()) {
        echo '<div class="forum"><div class="forum_Titel">' ,"Titel:  ".$row['fragen_title'].'</div>',
        "<br><br>",'<div class="forum_Subitel">', "Subtitel:  " .$row['fragen_subtitle'].'</div>',
        "<br><br>",'<div class="forum_Content">',"Text:  ".$row['fragen_content'].'</div>',
        "<br><br>",'<div class="forum_Bild"><img class="pic" alt="Ein Bild" title="Eine Pflanzen" src="'.$row['fragen_picture'].'">',
        "<br><br>","Bildlink:  ".$row['fragen_picture'].'</div>',
        "<br><br>",'<div class="forum_Upload-date">',"Upload-Datum:  ".$row['fragen_date'].'</div>',
        '</div>';

}
?>

现在它应该在SELECT * FROM WHERE fragen_id =网址ID的部分的文档顶部询问

i mean this id

1 个答案:

答案 0 :(得分:1)

查询字符串上的参数通过SELECT MAJR_CODE, MAJR_DESC, COUNT(*) FROM (SELECT se.*, ROW_NUMBER() OVER (PARTITION BY ID_KEY DESC ORDER BY TERM DESC) as seqnum FROM STUDENT_ENROLLMENT se WHERE TERM in ('201830', '201910', '201920') AND REGISTERED = 'Y' ) se WHERE seqnum = 1 GROUP BY MAJR_CODE, MAJR_DESC ORDER BY MAJR_CODE 数组传递给PHP。

因此$_GET仅需将其拾取并将其绑定到准备好的语句中的占位符

forum_forum.php