还是图片显示的问题,怎么老也解决不了呢,急啊

shijian58 2004-04-09 09:10:46
图片的显示是这样写吗,我想实现如果数据库里该条记录有图片则显示图片,如果没有则无显示或者提示[没有图片]。
<TD > <%
set rs=server.CreateObject ("adodb.recordset")
sql="select * from Company where CompanyID='"&request("CompanyID")&"'"
'response.Write sql
'response.End()
rs.open sql,conn,1,3
%> <table width="99%" border="0" cellpadding="0" cellspacing="1">
<tr align="left">
<form method="post" action="editcompany.asp?id=<%=rs("companyid")%>">
<td height="15" colspan="4" bgcolor="#006699">
<input type="submit" name="Submit2" value="企业大全信息修改"></td></form> </tr>
<tr>
<td width="149" align="right" valign="top" bgcolor="#D2EAFF" class="textBlack">
公司名称:</td>
<td width="171" bgcolor="#EEF7FF"> <%=rs("company")%></td>
<td colspan="2" rowspan="6" bgcolor="#EEF7FF"> 
//-----------------------------------------------
<% dim img,id
set rs1=server.CreateObject ("adodb.recordset")
sql1="select * from company where postid='"&request("companyid")&"'"
'response.Write sql1
'response.End()
rs1.open sql1,conn,1,3
img=rs1("logo")
Response.ContentType="image/*"
if img<>"" then
Response.BinaryWrite(img)
end if
rs1.close
set rs1=nothing
%>
//--------------------------------------------------------------
</td>
...全文
43 点赞 收藏 14
写回复
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kebeixueng 2004-04-29
还真管用
回复
wolf_fq 2004-04-09
在 showimg1.asp中不要使用response.write寫出任何提示的東西,不會顯示出來的,所以你的代碼隻能顯示圖片。沒有圖片就會顯示一個小方塊中間一個小叉。
你的代碼應該改成這樣就可以了:
showimg1.asp
<%
dim img,id
set rs1=server.CreateObject ("adodb.recordset")
sql1="select * from company where companyid='"&request("companyid")&"'"
'RESPONSE.Write SQL1
'RESPONSE.End()
rs1.open sql1,conn,1,1
Response.ContentType="image/*"
response.Buffer=true
n=rs1("logo").ActualSize
if n>0 then
Response.BinaryWrite(rs1("logo").getchunk(n))
end if
rs1.close
set rs1=nothing
%>
回复
wolf_fq 2004-04-09
不要寫

RESPONSE.Write SQL1
RESPONSE.End() 這裡已經終止了.
回复
shijian58 2004-04-09
我都改成这样了怎么还是不行啊
<!--#include file="../../conn/conn.asp"-->

<%
set rs=server.CreateObject ("adodb.recordset")
sql="select * from company where companyid='"&request("companyid")&"'"
'response.Write sql
'response.End()
rs.open sql,conn,1,3
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link rel="stylesheet" href="../../include/css.css" type="text/css">

</head>

<body>
<table width="99%" border="0" cellpadding="0" cellspacing="1">
<tr align="left">
<form method="post" action="editcompany.asp?id=<%=rs("companyid")%>">
<td height="15" colspan="4" bgcolor="#006699"> <input type="submit" name="Submit22" value="企业大全信息修改"></td>
</form>
</tr>
<tr>
<td width="149" align="right" valign="top" bgcolor="#D2EAFF" class="textBlack">
公司名称:</td>
<td width="171" bgcolor="#EEF7FF"> <%=rs("company")%></td>
<td colspan="2" rowspan="6" bgcolor="#EEF7FF">  <img src="showimg1.asp?companyid=<%=rs("companyid")%>"></td>
</tr>
--------------------------------------------------------------------------
showimg1.asp:
<%
dim img,id
set rs1=server.CreateObject ("adodb.recordset")
sql1="select * from company where companyid='"&request("companyid")&"'"
RESPONSE.Write SQL1
RESPONSE.End()
rs1.open sql1,conn,1,1
Response.ContentType="image/*"
response.Buffer=true
n=rs1("logo").ActualSize
if n>0 then
Response.BinaryWrite(rs1("logo").getchunk(n))
else
response.Write("没有LOGO")
end if
rs1.close
set rs1=nothing
%>
回复
flying310 2004-04-09
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
dim rs
dim cn
dim sql
set rs=server.CreateObject("adodb.recordset")
set cn=Server.CreateObject("ADODB.Connection")
cn.Open "数据库名称", "sa","密码"

sql="SELECT * FROM pic WHERE imageid = '" & Request.Item("tmid") & "'"
rs.Open sql,cn,1,1


'set rsTemp1=server.CreateObject("Adodb.recordset")
'rsTemp1.open strSQL,Con,3,2
'filesize=rsTemp1("filesize")
Response.ContentType="image/gif"
'Response.BinaryWrite content
'response.contenttype="x-mixed-replace"
Response.BinaryWrite rs("image")
'Response.BinaryWrite content
rs.Close

cn.close
set cn=nothing
在试试这段代码。
回复
stefli 2004-04-09
showImage.asp
----------------------------------------------------------------

<%
dim img,id
set rs1=server.CreateObject ("adodb.recordset")
sql1="select * from company where postid='"&request("companyid")&"'"
rs1.open sql1,conn,1,1
Response.ContentType="image/*"
response.Buffer=true
n=rs1("logo").ActualSize
if n>0 then
Response.BinaryWrite(rs1("logo").getchunk(n))
end if
rs1.close
set rs1=nothing
%>


主页面调用index.asp
------------------------------------------------------
<img src="showImage.asp?companyid=<%=rs("companyid")%>">
回复
wolf_fq 2004-04-09
代碼有問題,中間少寫了幾行關鍵的東西,查查以前的貼子,有很多關於圖片顯示的示例,
<% dim img,id
set rs1=server.CreateObject ("adodb.recordset")
sql1="select * from company where postid='"&request("companyid")&"'"
rs1.open sql1,conn,1,1
Response.ContentType="image/*"
response.Buffer=true
n=rs1("logo").ActualSize
if n>0 then
Response.BinaryWrite(rs1("logo").getchunk(n))
end if
rs1.close
set rs1=nothing
%>
回复
shijian58 2004-04-09
奇怪的问题!我将代码该成下面的以后再点击到这个页面的连接就提示下载该页面,WHY?
<%
set rs=server.CreateObject ("adodb.recordset")
sql="select * from company where companyid='"&request("companyid")&"'"
'response.Write sql
'response.End()
rs.open sql,conn,1,3
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link rel="stylesheet" href="../../include/css.css" type="text/css">

</head>

<body>
<table width="99%" border="0" cellpadding="0" cellspacing="1">
<tr align="left">
<form method="post" action="editcompany.asp?id=<%=rs("companyid")%>">
<td height="15" colspan="4" bgcolor="#006699"> <input type="submit" name="Submit22" value="企业大全信息修改"></td>
</form>
</tr>
<tr>
<td width="149" align="right" valign="top" bgcolor="#D2EAFF" class="textBlack">
公司名称:</td>
<td width="171" bgcolor="#EEF7FF"> <%=rs("company")%></td>
<td colspan="2" rowspan="6" bgcolor="#EEF7FF"> <% dim img,id
img=rs("logo")
Response.ContentType="image/*"

if not isNull(img) then
Response.BinaryWrite(img)
else
response.Write("暂缺LOGO")
end if
%></td>
</tr>
回复
shijian58 2004-04-09
to:林林
我是将图片存到数据库中的,所以不能读路径,这是是上面的要求,说这样读取图片快
回复
flying310 2004-04-09
Response.ContentType="image/*"
if img<>"" then
Response.BinaryWrite(img)
end if
代码是正确的。
回复
flying310 2004-04-09
在图片显示的时候做一下判断就好了。
<%if rs("image")="" then%>
没有要显示的图片
<%else%>
<img src="rs("image")">
<%end if%>
注:image是存入的图片的路径。
回复
stefli 2004-04-09
if not isNull(img) then
Response.BinaryWrite(img)
end if
回复
shijian58 2004-04-09
TO:inelm
我上面的代码对吗,怎么页面显示不出图片?
回复
nchen123 2004-04-09
做好一张 error.jpg 显示错误的图片。
<img src="xxx.jpg" onerror="this.src='error.jpg';">
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告