Link to home
Start Free TrialLog in
Avatar of NickRackham
NickRackham

asked on

Storing Photo's in acces and displaying in ASP

I've got an Internal phone directory that our users can query and display by asp.

Part One. I would like to include a photo of each person against their record in the access database, how do I achieve this?

Part Two. How do I get this displayed in the asp page along with all the other info?, Do I just add this column to the displyed info or?????

Detailed instructions would help as I'm nearly brain dead at the moment <g>

Nick
Avatar of NickRackham
NickRackham

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of MasseyM
MasseyM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, I followed your above comments but the image that is being displayed is the Red Cross symbol, i.e. not available. The properties indicate that it is http://myserver/photos/.gif and not http://myserver/photos/258.gif which is my photo. The access database has a unique number as the first column, autonumber, but the column name is ID, I've tried changing the Column name but that doesn't help either.

Nick
I've tried everything I can think of (at the moment) but whatever I do the image will not display and the properties for the error image are http://myserver/photos/.gif

Obviously not picking up the UniqueID for some reason. Please can you advise further.

I can't mail the database due to confidential data.

many thanks

Nick
OK... Can you send me the ASP page?  I will see what you have and then do what I can from there...

Also, the name of trhe "unique" ID is called "ID"?
Here's the entire code for the asp page

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<base target="MAIN">
<script>
//<!--
function ShowButtons() {
    if (window.top.frames.length!=0 && window.top.frames[0].ShowButtons!=null)
      window.top.frames[0].ShowButtons('/intr0002.htm','/intr0000.htm','','','');
}

//-->
</script>
<script language="javascript"><!--
function Title()
{
top.document.title=document.title;
}
//--></script>

<base target="MAIN">
<title>Phone Book Search Results</title>
</head>

<body onLoad="ShowButtons(), Title ()" text="#000000" topmargin="0" leftmargin="5"
bgcolor="#FFFFFF" link="#0000FF" vlink="#800080" alink="#FF0000">

<h2 align="center"><a name="top">Phone Book Search Results</a><small><small><small><small>
</small></small></small></small></h2>

<hr color="#000080">
<%
Param = Request.QueryString("Param")
Data = Request.QueryString("Data")
%>
<%
Session.timeout = 15
If IsObject(Session("Telephone_conn")) Then
    Set conn = Session("Telephone_conn")
Else
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open "Telephone","",""
    Set Session("Telephone_conn") = conn
End If
%>
<%
    sql = "SELECT PhoneBook.FirstName, PhoneBook.LastName, PhoneBook.Department, PhoneBook.Section, PhoneBook.JobTitle, PhoneBook.Location, PhoneBook.Extension, PhoneBook.DirectDial, PhoneBook.Email  FROM PhoneBook  WHERE (((PhoneBook.FirstName) Like '" & Request.QueryString("[FirstName]") & "%%') AND ((PhoneBook.LastName) Like '" & Request.QueryString("[LastName]") & "%%') AND ((PhoneBook.Department) Like '" & Request.QueryString("[Department]") & "%%') AND ((PhoneBook.Section) Like '" & Request.QueryString("[Section]") & "%%') AND ((PhoneBook.Location) Like '" & Request.QueryString("[Location]") & "%%') AND ((PhoneBook.Extension) Like '" & Request.QueryString("[Extension]") & "%%'))   "
    If cstr(Param) <> "" And cstr(Data) <> "" Then
        sql = sql & " And [" & cstr(Param) & "] = " & cstr(Data)
    End If
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, 3, 3
%>

<table BORDER="1" BGCOLOR="#FFFFFF" CELLSPACING="0" width="100%">
  <font FACE="Arial" COLOR="#000000"><thead>

  <tr>
    </font><font COLOR="#000000"><th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"></font><font
    COLOR="#000000" face="Arial" size="1">FirstName</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">LastName</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Department</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Section</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">JobTitle</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Location</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Extension</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">DirectDial</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Photo</font></th>
    <th BGCOLOR="#c0c0c0" BORDERCOLOR="#000000"><font COLOR="#000000" face="Arial" size="1">Email</font></th>
    <font FACE="Arial" COLOR="#000000">
  </tr>
</thead>
<tbody>
<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof
 %>
  <tr VALIGN="TOP">
    </font><font COLOR="#000000"><td BORDERCOLOR="#c0c0c0"></font><font COLOR="#000000"
    face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("FirstName").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("LastName").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("Department").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("Section").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("JobTitle").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("Location").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("Extension").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font COLOR="#000000" face="Arial" size="1"><%=Server.HTMLEncode(rs.Fields("DirectDial").Value)%><br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><font face="Arial" size="1"><%Response.write "<IMG SRC=""../photos/" & ID & ".gif"">" %> <br>
    </font></td>
    <td BORDERCOLOR="#c0c0c0"><p align="center"><font COLOR="#000000" face="Arial" size="1"><a
    href="<%=rs.Fields("Email")%>"><%if not rs.Fields("Email") = "" then%><img src="../images/mail.jpg" width="14" height="11"
    border="0" alt="Click to send Email" align="middle"><%end if%></a> <br>
    </font></td>
    <font FACE="Arial" COLOR="#000000">
  </tr>
<%
rs.MoveNext
loop%>
</tbody>
<tfoot>
</tfoot>
</table>

<hr color="#000080">

<p align="left"><a href="#top" target="_self"><img BORDER="0" SRC="../images/arrowtop.gif"
alt="Back to Top" WIDTH="14" HEIGHT="10"></a> <font size="1"
face="Verdana,Arial,Helvetica">Back to top</font></p>

<p align="left"><font face="Verdana" size="1">This Page was last Edited on <!--webbot
bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" --></font></p>

<p><!--"Page created by Nick Rackham"--></p>
</font>
</body>
</html>
UP here in this part of the code, you need to do this:

<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof
  ID = rs("UniqueID")
%>

This will set ID to the nique ID number... Be sure to replace "UniqueID" with the appropriate field in the database.

 
MasseyM

I'm still getting the little red cross icon (can't display image) and when I right click to see what the properties are it reports "http://myserver/photos/.gif"

For some reason it's not picking up the ID

the path to the image is OK, the number I'm trying to call is consistent.

Any thoughts?
What is the name of the field?  It is hard to do this blind, so I apologize...

Basicaly, you need to set ID to equal RS("UniqueID").

Then, to check what ID equals, do this:

response.write "Current ID: " & ID
No need to apologise I know what it's like <g>.

My access database has:-

ID = Autonumber
Title = Text
Forename = Text
Lastname = Text
Photo = Text (the number in this field = the ID autonumber)
More fields = Text

I have given the photo number the same as the ID autonumber as this will never change.

I take it that I need to use "photo" as the ID ? So would the relevant code above be:-

<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof
  ID = rs("Photo")
%>

with the relevant table entry being:-

<td BORDERCOLOR="#c0c0c0"><font face="Arial" size="1"><%Response.write "<IMG SRC=""../photos/" & ID & ".gif"">" %> <br>
    </font></td>

Hope this helps

Regards

Nick

PS. If we get really stuck I might be able to get a copy of the database, less data, and the html and asp pages mailed to you. But this may not be until tomorrow.
Nick,

Ok. You have a field called Photo?  If so, you would use the code as you listed above.  Make sure that the Photo field has a number in it though... If not, you can always use :

<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof
  ID = rs("ID")
%>

Since the ID is the autonumber.  Either way will work.  

There is really no need to have the "photo" field since it is equal to the ID field.  YOu can just use the ID field.

Many thanks for your perseverance. For some reason I started from scratch and it worked first time. Must have made an error that I couldn't see for looking.

Once again Thanks

Nick :o)
Good deal...  That sometimes happens... I start over a lot sometimes when things just aren't going right...

Good that it works...