Reputation: 99
Quick question. I'm doing this project for college. I'm learning php so please take it easy on me.
I need to create a dynamic link to a profile page. i.e website.php?id=70 Then I need to use $_Get['id'] and display relative information about that page.
I can't figure out what is wrong. There is no output if I use following code.
website.php page where the outcome is. Code in foreach loop is for testing purposes. This page is another file that other pages link to. Basically on this page is where I display information about that website.
<?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>';
}
?>
Upvotes: 0
Views: 174
Reputation: 37701
'{$id}'
this will never get parsed (it will simply output the string: '{$id}'
instead of '70'
for example) because of the single quotes thus you won't be getting any results selected. Double quotes are hused to parse variable inside them, However, since you're using integers, you can drop the quotes and (just to be safe), use (int) $id
:
$websites = DB::getInstance()->get('website', array('id', '=', (int) $id));
Upvotes: 2