繁体   English   中英

PHP链接到个人资料页面。 ?ID =

[英]PHP link to profile page. ?id=

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

我需要创建一个到配置文件页面的动态链接。 ie website.php?id = 70然后我需要使用$ _Get ['id']并显示有关该页面的相关信息。

我无法弄清楚出了什么问题。 如果我使用以下代码,则没有输出。

website.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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM