【发布时间】:2018-04-10 13:45:27
【问题描述】:
我正在尝试使用 PHP 回显数据库以显示我的整个表格,包括图像,但是当涉及到图像时,我得到的只是二进制代码。请帮忙:
PHP
<!Doctype html>
<html>
<head>
<title>connecting to a Database</title>
</head>
<body>
<?php
$con = mysql_connect('localhost','root','');
$db = mysql_select_db('dinnerpartydata');
if($con){
echo 'Successfully connected to the database.';
}else {
die('Error.');
}
if($db){
echo 'Successfully found the database';
}else {
die('Error. database not found.');
}
?>
<br />
<br />
<?php
$query= mysql_query("SELECT * from recipesnimages");
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$recipeType = $row['recipeType'];
$recipeName = $row['recipeName'];
$Instructions = $row['Instructions'];
$recipeImg = $row['recipeImg'];
echo $id . '| ' . $recipeType . '| ' . $recipeName . '| ' . $Instructions .'| ' . $recipeImg .'<br />';
}
?>
</body>
</html>
【问题讨论】:
-
您可能需要将其转换为图像并放入您正在打印的网页中: echo '”。当然,取决于您使用的确切格式。
-
嘿 kiteflight,我使用的是 150X150 的 jpg。我无法理解这种转换是如何工作的。你能用我的代码回复一个例子吗?
-
尝试像这样更改您的代码(仅当图像使用 base64 编码保存在数据库中时才有效,否则您必须适应您使用的格式): echo $id 。 '| ' . $recipeType 。 '| ' . $食谱名称。 '| ' . $指令。'| ' . .'
';
标签: php mysql database xampp backend