Just can't figure out how to do this..........
I have a simple asp page that desplays images from database.
The query on my page:
-------------------------
imagequery = "SELECT * FROM FILE_LIST WHERE CLASS_ID=" & FORM_ID
------------------------
The table FILE_LIST contains a field called TITLE which never gets
displayed.
(the form_id comes from a selection on previous page)
I display the images with a do loop as follows:
---------------------------
<%
set rstemp=conntemp.execute(imagequery)
If rstemp.EOF Then
Form_file_ID = 0
Else
do while not rstemp.eof
%>
<CENTER><IMG SRC="imagehelper.asp?FILE_id=<% = rstemp("FILE_id")
%>"></CENTER>
<%
rstemp.movenext
loop
END IF
rstemp.close
set rstemp=nothing
%>
--------------------------
I want to have the images that have the string 'photo' within the 'TITLE'
field disply FIRST
(eg. one with the title 'A photo of a cat' would desplay before 'A drawing
of a Cat' )
and THEN the ones that don'tt. I think I can accomplish this some kind of
if statement in the loop,
but I just cant get it to work without the ones containing 'photo'
displaying twice.
I hope I've explained this adequately.
Thanks in advance to anyone who has any ideas.
> Just can't figure out how to do this..........
> I have a simple asp page that desplays images from database.
What database? Type and version please ... these are almost always relevant
and they are definitely relevant for this question.
> The query on my page:
> -------------------------
> imagequery = "SELECT * FROM FILE_LIST WHERE CLASS_ID=" & FORM_ID
Nothing to do with your problem but ...
http://www.aspfaq.com/show.asp?id=2096
> ------------------------
> The table FILE_LIST contains a field called TITLE which never gets
[quoted text clipped - 4 lines]
> I hope I've explained this adequately.
> Thanks in advance to anyone who has any ideas.
I cannot get specific, but the sql dialect for whatever database you are
using undoubtedly has string functions to enable you to accomplish this in
your sql statement. Like this:
Access:
imagequery = "SELECT * FROM FILE_LIST " & _
"WHERE CLASS_ID=" & FORM_ID & _
" ORDER BY iif(Instr([TITLE],"photo")>0,0,1) ASC
SQL Server:
imagequery = "SELECT * FROM FILE_LIST " & _
"WHERE CLASS_ID=" & FORM_ID & _
" ORDER BY CASE WHEN TITLE Like '%photo%' " & _
"THEN 0 ELSE 1 END ASC"

Signature
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Randy - 02 Aug 2008 21:15 GMT
Thanks very much. Yes I should have specified which database type. As it
turns out I just switched from Access to SQL Server, and this query works
perfectly.
Also looked at the article you quoted. I'm in the process now of getting rid
of all those SELECT *'s.
>> Just can't figure out how to do this..........
>> I have a simple asp page that desplays images from database.
[quoted text clipped - 32 lines]
> " ORDER BY CASE WHEN TITLE Like '%photo%' " & _
> "THEN 0 ELSE 1 END ASC"
Bob Barrows [MVP] - 02 Aug 2008 21:59 GMT
> Thanks very much. Yes I should have specified which database type. As it
> turns out I just switched from Access to SQL Server, and this
> query works perfectly.
> Also looked at the article you quoted. I'm in the process now of
> getting rid of all those SELECT *'s.
Excellent. While you're at it, you might want to check this out:
Further points to consider:
Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23
See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/72e36
562fee7804e
Personally, I prefer using stored procedures:
http://groups.google.com/group/microsoft.public.inetserver.asp.general/msg/5d3c9
d4409dc1701?hl=en

Signature
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"