显示图片 [英] Displaying pictures
问题描述
你好
我正在开发一个在网页上显示几张图片的应用程序。
这些图片作为BLOB保存在MySQL数据库中。我注意到,网页
服务器通过打印图片而受到影响。让我们说
有20张图片要显示,还有20个查询要做。这是我现在这样做的
:
index.php
<?php
foreach($ icons as $ value){
echo''< img src =" ./ show_icon.php?icon_id =''。 $ value。 ''">'';
}
?>
show_icon.php
<?php
$ query =" SELECT icon FROM pictures WHERE id =''$ _ GET [''icon_id'']" ;;
$ result = @mysql_query($ query)或die(mysql_error());
$ icon = @mysql_result($ result,0," icon");
header(" Content-type:image / png");
echo $ icon;
?>
实际上这很有效,但性能是一个问题。
有比上面的代码更简单或更优雅的方式吗?有没有
实际上是用一个查询而不是20个查询来做到这一点的解决方案?
感谢您的帮助
Stefan
Hello
I am working on an applicaion that shows several pictures on a webpage.
These pictures are saved in a MySQL DB as BLOB. I noticed, that the web
server suffers in its performance by printing the pictures. Let''s say
there are 20 pictures to show, there also are 20 queries to do. This is
the way I am doing it up to now:
index.php
<?php
foreach ($icons as $value) {
echo ''<img src="./show_icon.php?icon_id='' . $value . ''">'';
}
?>
show_icon.php
<?php
$query = "SELECT icon FROM pictures WHERE id=''$_GET[''icon_id''] ";
$result = @mysql_query ($query) or die (mysql_error());
$icon = @mysql_result ($result, 0, "icon");
header("Content-type: image/png");
echo $icon;
?>
Actually this works quite well, but the performance is an issue. Is
there a more simple or more elegant way than the code above? Is there
actually a solution to do it with one query instead of 20 queries?
Thanks for your help
Stefan
推荐答案
图标为
value){
echo' '< img src =" ./ show_icon.php?icon_id =''。
value) {
echo ''<img src="./show_icon.php?icon_id='' .
值。 ''">'';
}
?>
show_icon.php
<?php
value . ''">'';
}
?>
show_icon.php
<?php
这篇关于显示图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!