title: displaying images from sql database with classic asp
body: <p>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?</p>
  
  <p>i am using classic asp and html/javascript.</p>
  
  <p>so far the code i have is:</p>
  
  <pre><code>&lt;img id="news_image2" alt="&lt;%=rsNews("Image_Name")%&gt;" border="0" height="70" name="Image" src="&lt;%=rsNews("news_Image")%&gt;" title="Echo_Images" width="80" align="middle" /&gt; &lt;/a&gt;   
  </code></pre>
  
  <p>Many thanks</p>
  
  <p>EDIT. tHE IS THE rsnews on homepage.asp</p>
  
  <pre><code>    &lt;%@  language="VBSCRIPT" codepage="1252" %&gt;
      &lt;!-- #include file="Connections/echo.asp" --&gt;
  &lt;%
  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 &gt;= 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
  %&gt;
  &lt;div id="news-home-container"&gt;
  
                           &lt;!--news item 1--&gt;
                          &lt;div&gt;
                             &lt;div class="news-home-image"&gt;
                                      &lt;a href="about/echo_news.aspx?id=0"&gt;
                                          &lt;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" /&gt;&lt;/a&gt; &lt;/div&gt;
  
                              &lt;div class="newsDiv"&gt;
                            &lt;a href="about/echo_news.aspx?id=0" &gt;&lt;b style="line-height:1.3em"&gt;&lt;%=rsNews("News_Title")%&gt;&lt;/b&gt;
                    &lt;p&gt;&lt;%=rsNews("News_Title_Header")%&gt;&lt;/p&gt;&lt;/a&gt;                                                                        
                       &lt;/div&gt;
                              &lt;/div&gt;
                           &lt;!--End of news item 1--&gt; 
  </code></pre>
  
  <p>now i need the images that are saved to the top 3 articles in the database to be displayed .</p>
  
  <p>this is the code in image_display.asp</p>
  
  <pre><code>    &lt;!-- #include file="Connections/echo.asp" --&gt;
  
  &lt;%
      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
  </code></pre>
  
  <p>' 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 =" &amp; 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</p>
  
  <pre><code>   'destroy the variables.
     rs.Close
      conn.Close
     set rs = Nothing
     set conn = Nothing
   %&gt;
  </code></pre>