我正在创建一个网站,并希望允许管理员添加从MySQL数据库提取的图像,并将其显示在要添加的新闻博客文本上方。我可以显示图像以及文本,但是它们被组合在一起(图像和图像以及文本)。我如何让我的网站显示在添加的最后一个文本条目上方输入的最后一个图像?
<?php
$sql = "SELECT imageId FROM output_images ORDER BY imageId DESC";
$result = mysqli_query($dbc, $sql);
?>
</BODY>
</HTML>
<div class="brown-container-fluid text-left">
<div class="text-home">
<h2><strong>Pine Lane News</strong></h2><br/>
<?php
if ($row = mysqli_fetch_array($result)) {
?>
<div style="text-align:center;">
<img style="max-width:300px; max-height:300px;"
src="imageView.php?image_id=<?php echo $row["imageId"]; ?>"/><br/>
</div>
<?php
}
$query = 'SELECT * FROM entries ORDER BY date_entered DESC';
if ($r = mysqli_query($dbc, $query)) { // Run the query.
// Retrieve and print every record:
while ($row = mysqli_fetch_array($r)) {
print
"<dl><dt><h3><strong>{$row['title']}</strong></h3></dt>
<dd>{$row['entry']}<br /><br />\n</dd></dl>";
}
} else { // Query didn't run.
print '<p style="color: red;">Could not retrieve the data because:<br />' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
} // End of query IF.
mysqli_close($dbc); // Close the database connection.
?>
</div>
</div>
答案 0 :(得分:0)
我想出了一个真正的快速方法,未经测试。
<?php
while($row = mysqli_fetch_array($result)){
echo '<div style="text-align:center;">';
echo '<img style="max-width:300px; max-height:300px;"';
echo 'src="imageView.php?image_id="'.$row["imageId"].'"/><br/>';
echo '</div>';
$query = 'SELECT * FROM entries ORDER BY date_entered DESC LIMIT 1';
if ($r = mysqli_query($dbc, $query)) { // Run the query.
while ($row = mysqli_fetch_array($r))
{
print
"<dl><dt><h3><strong>{$row['title']}</strong></h3></dt>
<dd>{$row['entry']}<br /><br />\n</dd></dl>";
}
} else { // Query didn't run.
print '<p style="color: red;">Could not retrieve the data because:<br />' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
} // End of query IF.
mysqli_close($dbc); // Close the database connection.
?>