PHP链接到个人资料页面.?id=.


PHP link to profile page. ?id=

快速问题。我正在为大学做这个项目。我正在学习php,所以请放轻松。

我需要创建一个指向个人资料页面的动态链接。 即网站.php?id=70 然后我需要使用 $_Get['id'] 并显示有关该页面的相关信息。

我不知道出了什么问题。如果我使用以下代码,则没有输出。

网站.php结果所在的页面。foreach 循环中的代码用于测试目的。此页面是其他页面链接到的另一个文件。基本上在此页面上,我显示有关该网站的信息。

 <?php
    require_once ('functions/sanitize.php');
    require_once('core/init.php');
    include('includes/header.php');
    require_once('classes/Websites.php');
    if(!$id = Input::get('id')){
        Redirect::to('index.php');
    } else {
        $websites = DB::getInstance()->get('website', array('id', '=', '{$id}'));
    }
?>
    <?php
        foreach ($websites as $website){
            echo '<div class="web-gallery margin-30 col-lg-4 col-md-6 col-sm-6 col-xs-12">';
        echo '<img class="sepImg" src="web-images/screenshots/' . escape($website->img) . '" alt="' . escape($website->web_name) . '">';
        echo '<div class="web-buttons">';
        echo '<a href="#"><div class="web-love"><img src="css/img/web-link.png" alt="web link"></div></a>';
        echo '</div>';
        echo '<div class="text-wrapper">';
        echo '<h4 class="text-center"><strong><a href="website.php?id=' . escape($website->id) . '">' . escape($website->web_name) . '</a></strong></h4>';
        echo '<h5 class="text-center"> Website Designed By: <strong>' . escape($website->designer) . '</strong></h5>';
        echo '<p class="text-center padding-text">' . escape($website->description) . '</p>';
        echo '</div>';
        echo '</div>';
        }
    ?>
'{$id}'

永远不会被解析(例如,它只会输出字符串:'{$id}'而不是'70'),因为单引号因此你不会得到任何结果选择。双引号用于解析其中的变量,但是,由于您使用的是整数,因此您可以删除引号并(为了安全起见),使用 (int) $id

$websites = DB::getInstance()->get('website', array('id', '=', (int) $id));