Displaying images from sql database with classic asp

asp-classic

i am creating a home page and have a news section. currently the news section displays the top 3 news titles/headlines from the database they are stored in. How the owner wants it now is that an image should be displayed next to the news headline relating to that news article. So i have set up a function where by they upload an image into the news database against the article they have just created/uploaded into the database, now all i want to do is display this image that is saved in the database. Is there a way to do this?

i am using classic asp and html/javascript.

so far the code i have is:

<img id="news_image2" alt="<%=rsNews("Image_Name")%>" border="0" height="70" name="Image" src="<%=rsNews("news_Image")%>" title="Echo_Images" width="80" align="middle" /> </a>   

Many thanks

EDIT. tHE IS THE rsnews on homepage.asp

    <%@  language="VBSCRIPT" codepage="1252" %>
    <!-- #include file="Connections/echo.asp" -->
<%
Dim rsNews
Dim rsNews_numRows

Set rsNews = Server.CreateObject("ADODB.Recordset")
rsNews.ActiveConnection = MM_echo_STRING
rsNews.Source = "SELECT top 3 News_Article_ID,News_Article_Create_Date,News_Txt_Date,News_Title,News_Publish_Date,News_Expiry_Date,News_Title_Header,News_Active,Admin_ID,News_Ticker,display,Image_Name,displayCode,news_Image FROM tblNews WHERE News_Active = 1 AND News_Expiry_Date >= getDate() AND (display = 'ext' OR display = 'both'OR displayCode=1 OR displayCode=4 OR displayCode=5 OR displayCode=7) ORDER BY News_TXT_Date DESC"
rsNews.CursorType = 0
rsNews.CursorLocation = 2
rsNews.LockType = 1
 rsNews.Open()

rsNews_numRows = 0
%>
<div id="news-home-container">

                         <!--news item 1-->
                        <div>
                           <div class="news-home-image">
                                    <a href="about/echo_news.aspx?id=0">
                                        <img id="news_image2" alt="LatestNews" border="0" height="70" name="logo_link0" src="image_display.asp?PhotoID=627" title="Echo_Images" width="80" align="middle" /></a> </div>

                            <div class="newsDiv">
                          <a href="about/echo_news.aspx?id=0" ><b style="line-height:1.3em"><%=rsNews("News_Title")%></b>
                  <p><%=rsNews("News_Title_Header")%></p></a>                                                                        
                     </div>
                            </div>
                         <!--End of news item 1--> 

now i need the images that are saved to the top 3 articles in the database to be displayed .

this is the code in image_display.asp

    <!-- #include file="Connections/echo.asp" -->

<%
    Dim sql
    Dim rs
    Dim conn
    Dim userID,str

   userID = Request("PhotoId")
   If userID = "" Then userID = 0

   'Instantiate Objects
   Set conn = Server.CreateObject("ADODB.Connection")
   Set rs = Server.CreateObject("ADODB.Recordset")

   'Open connection

' rsNews.ActiveConnection = MM_echo_STRING
'conn = uncomment this line and insert your connection string here
'Get the specific image based on the ID passed in a querystring
str = "SELECT news_Image FROM tblNews WHERE news_article_id =" & userID
rs.Open str, conn,3,3
if rs.eof then 'No records found
Response.End
else 'Display the contents
Response.ContentType = "image/gif"
Response.BinaryWrite(rs("news_Image"))
end if

   'destroy the variables.
   rs.Close
    conn.Close
   set rs = Nothing
   set conn = Nothing
 %>

Best Answer

i figured it out. the issue was that the image was not been loaded into the database correctly so i recreated the page where the image was loaded and then used Jatins code above, only altering the "ID" to "News_Article_ID". once this was done i entered the following code into the img source

img src="Image_Display.asp?news_Article_iD=<%=rsnews("News_article_id")%>"

many thaks for your help everyone

Related Topic