<?php
include 'connection.php';
$recipeid = $_GET['recipeid'];
if (empty($recipeid) || !is_numeric($recipeid)){
	header ("Location: index.php");
}

$sql = $dbh->prepare("select * from rec_recipes where id = ?");
$sql->bindValue(1,$recipeid,PDO::PARAM_INT);
$sql->execute();
while ($row = $sql->fetch()){
	$id = $row[0];
	$title = $row[1];
	$recipe = $row[2];
	echo '<h1>'.$title.'</h1>';
	echo '<img src ="images/'.$id.'.jpg" alt="'.$title.'" height="400"/><br>'; 
	echo $recipe.' <button onclick="window.print();">Print</button><br><br><br>';
	echo '<h3>Comments</h3>';
	$innersql = $dbh->prepare("select rec_users.username,rec_comments.comment
		from rec_users,rec_comments
		where rec_comments.userid = rec_users.id 
		and rec_comments.recipeid = ? order by rec_comments.id desc");
	$innersql->bindValue(1,$recipeid,PDO::PARAM_INT);
	$innersql->execute();
	while ($innerrow = $innersql->fetch()){
		$username = $innerrow[0];
		$comment = $innerrow[1];
		echo '<p>'.$comment.'</p>';
		echo '<p><strong>'.$username.'</strong>';
	}


}
















?>