English 中文(简体)
表格中显示数据库作为电池的图像
原标题:Display image from database as a cell in a table
  • 时间:2011-11-10 03:49:38
  •  标签:
  • php
  • mysql

因此,我正在执行一个赞助管理网站,然后我遇到了一些麻烦。 我知道,将图像储存到数据库中可能会在颈部造成这种痛苦,但需要这样做(禁止制作一个档案系统,储存校园服务器中的图像)。

我设立了3个表格:

  • a info table storing text information,
  • an image table storing images in BLOB fashion and
  • a id_table table as a reference table keeping records of image id and info id.
$result=mysql_query("SELECT info_id,info_name,info_year,info_level,info_email,info_describe FROM info");
while($row = mysql_fetch_array($result))
{
    echo "<td>" . $row[ info_name ] . "</td>";
    echo "<td>" . $row[ info_year ] . "</td>";
    echo "<td>" . $row[ info_level  ] . "</td>";
    echo "<td>" . $row[ info_email ] . "</td>";
    echo "<td>" . $row[ info_describe ] . "</td>";
    $result_image_id = mysql_query("SELECT id_image FROM id_table WHERE id_info =  {$row[ info_id ]} ");
    $row_image = mysql_fetch_array($result_image_id);
    $result_image = mysql_query("SELECT image_stuff FROM image WHERE image_id =  {$row_image[ id_image ]} ");
    $row_2 = mysql_fetch_array($result_image);
    $content=$row_2[ image_stuff ];
    echo "<td>" ;
    header( Content-type: image/jpeg );
    echo $content;
    echo "</td>";
    echo "</tr>";
}

Then in the browser, I was redirected to a blank page. If I delete that header function, I do have a table in the page but there is nothing in the image column.

任何建议?

Additionally, I tried using an <img> tag in my while loop:

echo "<img src= $content  />";

好消息是,这种新闻是编造的,但图像档案实际上没有显示。

我的网页上有一个带有图像档案的图像栏的表格,但像服务器一样看不到图像。

I guess there does not exist any problem with my insert script because when I was applying that img tag,the "cannot display" logo only appeared in the cell whose row is the one I did upload image file into database...

最佳回答

你们可以像这样的头脑。

try something like that

$result=mysql_query("SELECT info_id,info_name,info_year,info_level,info_email,info_describe FROM info");
while($row = mysql_fetch_array($result))
{
echo "<td>" . $row[ info_name ] . "</td>";
echo "<td>" . $row[ info_year ] . "</td>";
echo "<td>" . $row[ info_level  ] . "</td>";
echo "<td>" . $row[ info_email ] . "</td>";
echo "<td>" . $row[ info_describe ] . "</td>";
$result_image_id = mysql_query("SELECT id_image FROM id_table WHERE id_info =  {$row[ info_id ]} ");
$row_image = mysql_fetch_array($result_image_id);
$result_image = mysql_query("SELECT image_stuff FROM image WHERE image_id =  {$row_image[ id_image ]} ");
$row_2 = mysql_fetch_array($result_image);
$content=$row_2[ image_stuff ];
echo "<td>" ;
echo  <img src="data:image/png;base64,  . base64_encode($content) .  " /> ;
echo "</td>";
echo "</tr>";
}

改变你所储存的任何类型的形象。 我很想一下这部法典,但这应该奏效。

问题回答

echo "" . $row [ post_image ] . ""





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签