我有这个代码应该从我的服务器获取图像并将其显示在我的html上。我的图像在md5中加密,当将它们上传到服务器时,我的表中没有存储图像名称的字段。因此,我使用表中的主键调用图像来获取图像。
这是我的代码:
<?php
// connection string constants
define('DSN', 'mysql:dbname=mydbname;host=localhost');
define('USER', 'myuser2015');
define('PASSWORD', 'mypwd2015');
// pdo instance creation
$pdo = new PDO(DSN, USER, PASSWORD);
// query preparation
$stmt = $pdo->query("
SELECT title, introtext, id, created, created_by, catid
FROM mytbl_items LIMIT 4
");
// fetching results
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
// if this returns 0 then it means no records are present
echo count($result) . "\n";
// the loop should print valid table
foreach ($result as $index => $row) {
if ($index == 0) echo '<div>';
echo <<<HTM
<img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";
<span class="post-date">{$row['created']}</span>
<h2 class="blog-post-title">{$row['title']}</h2>
<p>
{$row['introtext']}
</p>
<p>
<a href='read.php?id={$row['id']}'><input type="button" value="Read More" /></a>
</p></br>
<div class="blog-meta">
<img src="img/icons/logo.png" alt="Avatar" />
<h4 class="blog-meta-author">{$row['created_by']}</h4>
<span>Category: {$row['catid']}</span>
</div>
HTM;
if ($index == (count($result)-1))echo '</div>';
}
我使用应该获取图像的代码犯了什么错误?这是
行img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";
答案 0 :(得分:0)
从here / nowdoc中删除第二个echo
。您已经开始echo
进入
echo <<<HTM