Author |
Topic  |
|
Alfred
Senior Member
   
USA
1527 Posts |
Posted - 04 November 2003 : 14:51:13
|
I have a number of graphics (flags in this case) which I would like to call on depending on the field value in the database (M_COUNTRY in this case). The one way I know of would be to gather the values: strSQL = "select M_NAME, M_COUNTRY from FORUM_MEMBERS" set myFlags = my_Conn.Execute(strSql)
and then use a simple if statement in a loop to display the graphic : quote: do while not myFlags.eof if myFlags("M_COUNTRY") = "USA" then response.write myFlags("M_NAME") & "<img border=""0"" src=""../images/usa.gif""><br>" end if myFlags.movenext loop
It works ok here: http://www.ggholiday.com/bg/forums/test.ASP
Since I would have to use over 40 if statement in that loop for all the countries of my members, there is probably a simpler way to code this - I suspect something like a "case" statement, which I don't know how to use yet (the MSDN library is confusing me, and shows no practical example of one!http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsstmSelectCase.asp)
Could someone please give me a basic example of how to define cases or suggest another way to do this? |
Alfred The Battle Group CREDO
|
|
altisdesign
Junior Member
 
United Kingdom
357 Posts |
Posted - 04 November 2003 : 14:55:36
|
If I was doing this, I would use the same image names as the country names from the database so you avoid the whole problem of case or if statements. This is a lot more efficient IMO. I would remove the spaces from the country names to convert them into a valid image name eg.
do while not myFlags.eof
response.write myFlags("M_NAME") & "<img border=""0"" src="""&replace(myFlags("M_COUNTRY")," ","")&".gif""><br>"
myFlags.movenext
loop
<edit>forgot about the .gif / .jpg extension as approrpiate </edit>
|
Altis Design offers all manner of web design services to a variety of commercial and personal clients |
Edited by - altisdesign on 04 November 2003 14:56:49 |
 |
|
Alfred
Senior Member
   
USA
1527 Posts |
Posted - 04 November 2003 : 15:48:38
|
I understand what you say, and was able to get it to display after initial failure (had to change the folder destination in the code) quote: do while not myFlags.eof response.write myFlags("M_NAME") & "<img border=""0"" src="""&"../images/"&replace(myFlags("M_COUNTRY")," ","")&".gif""><br>" myFlags.movenext loop
It works for most nations,(http://www.ggholiday.com/bg/forums/test2.ASP) but it does not display those where the user has entered a country name different to the file name in the graphic. I suppose I could go through these manually and change the names, or display a text like "none available" etc. This is great - could you clear up one thing that is a bit puzzling: I am unfamiliar with the replace statement: The (myFlags("M_COUNTRY")," ","")&" provides a space in place of the name, right? But what does the next ""do?
|
Alfred The Battle Group CREDO
|
 |
|
altisdesign
Junior Member
 
United Kingdom
357 Posts |
Posted - 04 November 2003 : 15:55:01
|
My recommendation would be to change these names to match with the country name in the database without the space. eg. If the country in the database is "United Kingdom" then you would need an image called "unitedkingdom.gif" (or .jpg / png as the case may be). This has got to be better than loads of if / case statements.
The replace statement removes all of the spaces from the country name from the database. MSDN Docs: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsmthreplace.asp
I thought the removal of the space was a good idea because sometimes spaces can cause problems with image names, I'm not so sure it applies with newer browsers, but I have a feeling it may have applied with older browsers, with the image not being displayed. Anyway, its best to avoid AFAIK, so this line:
myFlags("M_COUNTRY")," ","")
The " " tells it to search for all spaces in the country name from the database. The "" tells it to replace all of these spaces with nothing, so in effect they are deleted 
HTH -Altis Design |
Altis Design offers all manner of web design services to a variety of commercial and personal clients |
 |
|
altisdesign
Junior Member
 
United Kingdom
357 Posts |
Posted - 04 November 2003 : 16:05:34
|
OK looking at this page I wrote a little add on for you from this page: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=78 - assuming your server supports FileSystemObject. I havn't tested this script, but it should work, you may need to change the path info, I've commented it with what is going on. It basically checks if a flag exists for the given country, and if it doesnt then it writes out "noflag.gif", otherwise the flag is displayed, getting rid of the red xs.
'iterate through all the members
do while not myFlags.eof
'writes out name of member
response.write myFlags("M_NAME")
'create instanse of FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
'checks file exists of relevant country (change path if needed)
If FSO.FileExists( Server.MapPath( "images/" & replace(myFlags("M_COUNTRY")," ","") &".gif" ) ) Then
'File exists, flag found, show flag
Response.write "<img border=""0"" src="""&replace(myFlags("M_COUNTRY")," ","")&".gif""><br>"
Else
'File does not exist, no flag found, show not available image
Response.write "<img border=""0"" src=""noflag.gif""><br>"
End If
'cleanup
set fso = nothing
'go through entire recordset
myFlags.movenext
loop
Hope this helps  -Altis Design |
Altis Design offers all manner of web design services to a variety of commercial and personal clients |
Edited by - altisdesign on 04 November 2003 16:07:01 |
 |
|
Alfred
Senior Member
   
USA
1527 Posts |
Posted - 04 November 2003 : 17:21:11
|
Ok, this is plenty for me to work with, and more than I expected to achieve. I very much appreciate your extensive and detailed explanation and instruction - and I actually understand it as well. Which is a bonus, because it gives me a chance to use it in other situations. I will now apply it to the page it was intended for:http://www.ggholiday.com/bg/forums/decorated.asp How does it look (provided you realize it is meant for games)?
|
Alfred The Battle Group CREDO
|
 |
|
altisdesign
Junior Member
 
United Kingdom
357 Posts |
Posted - 04 November 2003 : 17:27:28
|
You're welcome . Glad you understand it.. and also its better to be able to apply it than just copy and paste. What you've done there with the medals looks good I like it. A lot more authentic then just with the medals alone, to have flags as well. I might look at putting a similar flag mod on one of my modded forums, just in topic.asp. |
Altis Design offers all manner of web design services to a variety of commercial and personal clients |
 |
|
Alfred
Senior Member
   
USA
1527 Posts |
Posted - 04 November 2003 : 17:32:29
|
Thanks! The site I run is for a strategic gaming club. Over the last several months, with all the help I found in this forum, I have been able to improve the looks and mostly the functionality of my site tremendously. Here is another page you may like - the competition ladder: http://www.ggholiday.com/bg/FORUMS/Ladder.asp |
Alfred The Battle Group CREDO
|
 |
|
|
Topic  |
|