$db = get_db();
$posts = $db->query('SELECT
- p.ID, p.TIMESTAMP, pi.MIME_TYPE, pi.PIC_B64, c.BODY
+ p.ID as POST_ID,
+ p.TIMESTAMP,
+ pi.ID as PIC_ID,
+ pi.MIME_TYPE,
+ pi.PIC_B64,
+ c.BODY
FROM posts p
JOIN pics pi on p.id = pi.post_id
JOIN comments c on p.id = c.post_id
while ($post = $posts->fetchArray()) {
$mime_type = $post['MIME_TYPE'];
$file_b64 = $post['PIC_B64'];
- $post_id = $post['ID'];
+ $post_id = $post['POST_ID'];
+ $pic_id = $post['PIC_ID'];
$comment_text = $post['BODY'];
$img = new Imagick();
$img->readImageBlob(base64_decode($file_b64));
echo "<div id='post-{$post_id}'>";
- echo "<img src='data:{$mime_type};base64,{$compressed_b64}' alt='$'/>";
+ echo "<a href='pic/{$pic_id}'> <img src='data:{$mime_type};base64,{$compressed_b64}' alt='$'/></a>";
echo "<p>{$comment_text}</p>";
echo '</div>';
}